Write a program that loads several numbers from the keyboard,
asking in the meantime, the question "Do you want to finish: Y / N?"
At the end of the loop, program should display calculated values of:
the arithmetic average, maximum, minimum of given numbers.
#include <iostream>
#include <string>
using namespace std;
int main() {
double sum=0, min_val, max_val, val;
int n=0;
string ans;
do {
cout << "Enter a integer value ";
cin >> val;
if (n == 0) {
min_val = max_val = val;
}
sum += val;
n++;
if (min_val > val) {
min_val = val;
}
if (max_val < val) {
max_val = val;
}
while (true) {
cout << "Do you want to finish: Y/N: ";
cin >> ans;
if (ans[0] == 'Y' || ans[0] == 'N') {
break;
}
}
} while (ans[0] == 'N');
double avg = sum / n;
cout << endl;
cout << "Arithmetic average: " << avg << endl;
cout << "Maximum: " << max_val << endl;
cout << "Minimum: " << min_val << endl;
return 0;
}
Comments
Leave a comment