Answer to Question #191930 in C++ for Rahel Aschalew

Question #191930

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
2021-05-14T12:07:08-0400
#include <iostream>

int main()
{
    const int NUMBERS_COUNT = 10;
    
    std::cout << "Please enter " << NUMBERS_COUNT <<" integers: ";

    int count = 0;
    
    for(int i=0; i<NUMBERS_COUNT; ++i)
    {
        int tmp;
        std::cin >>tmp;

            if(!std::cin || tmp < 0 || tmp > 100)
            {
                std::cout << "Bad input\n";
                return 1;
            }

        if(tmp > 50)
        {
            ++count;
        }
    }

    std::cout << "The number of integers larger than 50 is " << count << "\n";

    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

No comments. Be the first!

Leave a comment