1. Write a program that prompts the user to enter five test scores and then prints the average test score. (Assume that the test scores are decimal numbers.)
#include <iostream>
int main()
{
float s1, s2, s3, s4, s5;
std::cout << "Enter five test scores: ";
std::cin >> s1 >> s2 >> s3 >> s4 >> s5;
if(!std::cin)
{
std::cout << "Error: invalid data\n";
return 1;
}
std::cout << "Average test score is " << ((s1 + s2 + s3 + s4 + s5) / 5) << "\n";
return 0;
}
Comments