#include <iostream>
using namespace std;
int main() {
// array for 10 integers
int num[10];
// read 10 integers from the keyboard
int i = 0;
while (i < 10) {
int n;
cout << "Input integer #" << i+1 << " in the range 0-100: ";
cin >> n;
// if the integer is less then 0 or larger than 100
if ( (n < 0) || (n > 100) ) {
// display error message
cout << "Error: Integer must be in the range 0-100" << endl;
} else {
// store integer to array
num[i] = n;
i++;
}
};
// count how many of integers are larger than 50
int counter = 0;
for (int i=0; i<10; i++) {
if (num[i] > 50) counter++;
}
// display result
cout << "Number of integers are larger than 50 is " << counter << endl;
// terminate program
return 0;
}
Comments
Nice job it make easy . Thanks so much
Leave a comment