fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. // This function calculates the average and the maximum number
  5. void calculate(float a, float b, float c, float &average, float &maximum) {
  6. average = (a + b + c) / 3; // calculate average
  7.  
  8. // find maximum number
  9. maximum = a;
  10. if (b > maximum) maximum = b;
  11. if (c > maximum) maximum = c;
  12. }
  13.  
  14. int main() {
  15. float num1, num2, num3;
  16. float avg, max;
  17.  
  18. // Ask user to enter 3 numbers
  19. cout << "Enter three numbers: ";
  20. cin >> num1 >> num2 >> num3;
  21.  
  22. // Call the function (by reference)
  23. calculate(num1, num2, num3, avg, max);
  24.  
  25. // Print results
  26. cout << "Average = " << avg << endl;
  27. cout << "Maximum = " << max << endl;
  28.  
  29. return 0;
  30. }
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
Enter three numbers: Average = -nan
Maximum = 4.59149e-41