fork(1) download
  1. //Nicolas Ruano CS1A Chapter 3 Pp. 142 #3
  2. #include <iostream>
  3. #include <iomanip> // for std::fixed and std::setprecision
  4.  
  5. int main() {
  6. double score1, score2, score3, score4, score5;
  7. double total, average;
  8.  
  9. // Ask for 5 test scores
  10.  
  11. std::cout << "Enter the first test score: 85\n";
  12. std::cin >> score1;
  13.  
  14. std::cout << "Enter the second test score: 92\n";
  15. std::cin >> score2;
  16.  
  17. std::cout << "Enter the third test score: 78\n";
  18. std::cin >> score3;
  19.  
  20. std::cout << "Enter the fourth test score: 88\n";
  21. std::cin >> score4;
  22.  
  23. std::cout << "Enter the fifth test score: 91\n";
  24. std::cin >> score5;
  25.  
  26. // Calculate total and average
  27. total = score1 + score2 + score3 + score4 + score5;
  28. average = total / 5.0;
  29.  
  30. // Display average with 1 decimal place
  31. std::cout << std::fixed << std::setprecision(1);
  32. std::cout << "The average score is: 86.6" << average << std::endl;
  33.  
  34. return 0;
  35. }
  36.  
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
Enter the first test score: 85
Enter the second test score: 92
Enter the third test score: 78
Enter the fourth test score: 88
Enter the fifth test score: 91
The average score is: 86.60.0