Write a program that will compute the average of a set of decimal numbers provid
ID: 3659269 • Letter: W
Question
Write a program that will compute the average of a set of decimal numbers provided by the user. The program will ask the user to enter numbers one at a time.
The user will enter numbers and the program will keep a count of the numbers entered. At the end, the program will display the sum, the count and the average of the numbers. See Test section below for test data.
Implementation
Use cin for inputing numbers. When the user presses ctrl-z followed by return key twice, cin becomes NULL.
Testing
Input Test Run 1
Enter a number:
10.2
Enter a number:
50.4
Enter a number:
40.6
Enter a number:
20.8
Enter a number:
30.0
Enter a number:
Output Test Run 1
Sum: 152.0
Count: 5
Average: 30.4
Explanation / Answer
#include using namespace std; int main() { int count=0; double sum=0; double average; double input; coutinput; while(cin) { count++; sum+=input; coutinput; } average = sum/count; coutRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.