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.
#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;
}
Comments
Leave a comment