fork(1) download
  1. // If you are not sure what some lines of code do, try looking back at
  2. // previous example programs, notes, or email a question.
  3.  
  4. #include <iostream>
  5.  
  6. using namespace std;
  7.  
  8. // A function that will return an integer, and takes an integer and a double as parameters
  9. int calc(int one, double two);
  10.  
  11. // A function that will not return anything, and takes two doubles as parameters
  12. void displayDbls(double disp1, double disp2);
  13.  
  14. int main() {
  15. int value_one = 60;
  16. double value_two = 0.89;
  17.  
  18. int result;
  19.  
  20. // Call the function calc. Note that the actual parameters do not need
  21. // to have the same names as the formal parameters.
  22. result = calc(value_one, value_two);
  23.  
  24. // Display the result
  25. cout << "calc result: " << result << endl << endl;
  26.  
  27. // Call the function displayDbls using literal values. Note that no return value
  28. // is captured, as displayDbls returns void.
  29. displayDbls(5.67, 10.436);
  30.  
  31. return 0;
  32. }
  33.  
  34. // Implementation of calc
  35. int calc(int one, double two) {
  36. // Do some sort of calculation
  37. int result = -(one / two) * (one - two) / (-5648 / (one += two));
  38.  
  39. // Return the result
  40. return result;
  41. }
  42.  
  43. // Implementation of displayDbls
  44. void displayDbls(double disp1, double disp2) {
  45. // Output the two parameters to the console
  46. cout << "Double value 1: " << disp1 << endl
  47. << "Double value 2: " << disp2 << endl;
  48.  
  49. }
Success #stdin #stdout 0s 3456KB
stdin
Standard input is empty
stdout
calc result: 42

Double value 1: 5.67
Double value 2: 10.436