Question #260765

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.)


Expert's answer

#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;    
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS