fork download
  1. //Amari Mosley CSC5 Chapter 3, P. 143, #3
  2. //
  3. /**************************************************************
  4.  *
  5.  * Test Average
  6.  * ____________________________________________________________
  7.  * This program asks for five test scores and calculates the
  8.  * average test score.
  9.  * Computation is based on the following formulas:
  10.  * average = (test1 + test2 + test3 + test4 + test5) / 5.0
  11.  * ____________________________________________________________
  12.  * INPUT
  13.  * test1, test2, test3, test4, test5
  14.  * OUTPUT
  15.  * average
  16.  *
  17.  **************************************************************/
  18. #include <iostream>
  19. #include <iomanip>
  20. using namespace std;
  21.  
  22. // Defining Main Function
  23. int main() {
  24. // Define variables to hold the five test scores and the average
  25. double test1, test2, test3, test4, test5, average;
  26.  
  27. // Ask the user to enter the five test scores
  28. cout << "Enter test score 1: ";
  29. cin >> test1;
  30. cout << "Enter test score 2: ";
  31. cin >> test2;
  32. cout << "Enter test score 3: ";
  33. cin >> test3;
  34. cout << "Enter test score 4: ";
  35. cin >> test4;
  36. cout << "Enter test score 5: ";
  37. cin >> test5;
  38.  
  39. // Calculate the average test score
  40. average = (test1 + test2 + test3 + test4 + test5) / 5.0;
  41.  
  42. // Format the output in fixed-point notation with one decimal point of precision
  43. cout << fixed << setprecision(1);
  44.  
  45. // Display the average test score
  46. cout << "The average test score is: " << average << endl;
  47.  
  48. return 0;
  49. }
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
Enter test score 1: Enter test score 2: Enter test score 3: Enter test score 4: Enter test score 5: The average test score is: 0.0