Answer to Question #84000 in Algorithms for chuchu

Question #84000
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-04T04:44:17-0500

#include <iostream>

int main() {

/* signed */ int number;

unsigned /* int */ counter, counter2;

std::cout << "Enter 10 integers in the range 0-100 and EOF\n";

counter = 0, counter2 = 0;

std::cin >> number;

while (!std::cin.eof() && !std::cin.fail() && counter < 10

&& number >= 0 && number <= 100) {

counter += 1;

if (number > 50) {

counter2++;

}

std::cin >> number;

}

if (counter == 10 && std::cin.eof()) {

std::cout << counter2 << " of the numbers are larger than 50\n";

} else {

std::cout << "The input contents were unexpected\n";

}

}

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

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS