made a program that displays the sum, the minimum value entered, the maximum value entered. But Don't know how to print out the number of items entered.
#include <iostream>
using namespace std;
int main()
{
double sum = 0, mean = 0, min = 0, max = 0;
while(true){
double num;
cout << "Enter a number(0 to exit): ";
cin >> num;
if(num == 0){
break;
}
sum += num;
mean++;
if(min > num){
min = num;
}
if(max < num){
max = num;
}
}
double avg = sum /mean;
cout << "Sum of all num = " << sum << endl;
cout << "Minimm of all numbers = " << min << endl;
cout << "Max of all numbers = " << max << endl;
cout << "Average of all numbers = " << avg << endl;
}
#include <iostream>
usingnamespace std;
int main()
{
double sum = 0, mean = 0, min = 0, max = 0;
int countItemsEntered = 0; // counter
while (true) {
double num;
cout << "Enter a number(0 to exit): ";
cin >> num;
countItemsEntered++; // count each number inputted.
if (num == 0) {
break;
}
sum += num;
mean++;
if (min > num) {
min = num;
}
if (max < num) {
max = num;
}
}
double avg = sum / mean;
cout << "Sum of all num = " << sum << endl;
cout << "Minimm of all numbers = " << min << endl;
cout << "Max of all numbers = " << max << endl;
cout << "Average of all numbers = " << avg << endl;
cout << "Total number of items entered = " << countItemsEntered << endl; // Print it out the total counter.
}