Answer to Question #84003 in C++ for chuchu

Question #84003
Read 10 integers from the keyboard in the range 0 -100, and count how many of them are larger than 50, and display this result.
1
Expert's answer
2019-01-07T12:06:10-0500

#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;

}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

JOSEPH TADESSE
28.10.23, 21:03

Nice job it make easy . Thanks so much

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS