Question: I am having some trouble with writing this program. I think the biggest issue is that I cannot figure out is how to get the
I am having some trouble with writing this program. I think the biggest issue is that I cannot figure out is how to get the program to end when the user enters 0.
This is the assignment: Write a code that asks the user to keep entering numbers. When the user enters 0 the program should show the count of how many numbers were entered, the total, average, highest and lowest of the numbers numbers. Use a priming read sentinel controlled loop.
USING C++
USE THE FOLLOWING ORDER FOR YOUR PRIMING READ SENTINEL LOOP CODE // vars for total & count, set them to 0 // var for num // read num // vars for min & max, set them to num // while ( num not sentinel ) // IFs to check/set new min and max // add num into total // increase count // read num again // // average and print results
AVERAGE should display as a decimal number!
Enter several numbers (0 to quit): 4 2 8 6 12 10 22 0 Count: 7 Total: 64 Average: 9.1 Highest: 22 Lowest: 2
Here is my current code: #include
int main(){ int count = 0; int total = 0; int num; cout << "Enter several numbers (0 to quit):" << endl; cin >> num; // priming read int max = num; int min = num; while (num != 0);{ if (num > max){ max = num; cin >> num; } if (num < min){ min = num; cin >> num; } } total += num; cin >> num; count ++; double average = total/(double)count ; cout<<"Count: "<
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
