Answer to Question #71225 in C++ for dine adem

Question #71225
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
2017-11-23T06:25:07-0500
#include <iostream>
using namespace std;
int main()
{
int n,counter=0,i=1;
while(i<=10)
{
cout<<"Enter value"<<i<<" between 0 to 100 inclusive: ";
cin>>n;
if(cin.fail()||n<0||n>100)
{ cout<<"\nvalue must be 0 - 100 inclusive"<<endl;
cin.clear(); // clears the error flag
cin.ignore(24,'\n'); // Extracts characters from the input sequence and
// discards them
}
else if (n>50)
{
counter++; // count larger than 50
i++; // next input
}
else
i++; // next input
}
cout<<"\nlarger than 50 "<<counter<<endl;
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

LATEST TUTORIALS
APPROVED BY CLIENTS