Answer to Question #159474 in C++ for Jonathon Hollingsworth

Question #159474

To get the average of a series of values, you add the values up and then divide the total by the number of values.

Write a program that stores the following values in seven different variables: 14, 32, 104, 63, 89, 125, 213.

The program should first calculate the total of these seven variables and store the result in a separate variable named total.

Then, the program should divide the total variable by seven to get the average. Display the average on the screen.


1
Expert's answer
2021-01-28T17:54:51-0500
#include <iostream>

int main() {
    int x1=14, x2=32, x3=104, x4=63, x5=89, x6=125, x7=213;
    int total = x1 + x2 + x3 + x4 + x5 + x6 + x7;
    double average = total / 7.0;
    
    std::cout << "Average value is " << average << std::endl;
    
    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!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog