Lab Exc. Mark Score Exercise# 1: Numbers Count a program that reads N numbers in
ID: 3588515 • Letter: L
Question
Lab Exc. Mark Score Exercise# 1: Numbers Count a program that reads N numbers in the interval [1, 100] and count how many is between 1 and 50, and how many is between 51 and 100. If the user enters a number outside the interval then the progra asks the user to try again and ignores the entered number. Sample input/output How many numbers you want to read? 7 Enter a number between 1 and 100: 34 Enter a number between 1 and 180: 79 Enter a number between 1 and 108: 21 Invalid number! try again. Enter a number between 1 and 100:e Invalid number! try again. Enter a number between 1 and 180: 33 Enter a number between 1 and 188: 81 Enter a number between 1 and 108: 92 Enter a number between 1 and, 100: 66 Enter a number between 1 and 100: 35e Invalid number! try again. Enter a number between 1 and 10e: 51 There are 2 numbers in the interval'[1, 5] There are s numbers in the interval [s1, 100] 3Explanation / Answer
#include <iostream.h>
int main()
{
int i,n,c1=0,c2=0,a;
cout << " How many numbers you want to read : " ;
cin >> n;
for (i=1;i<=n;i++)
{
if (i > n)
break;
cout << " Enter number between 1 and 100 : ";
cin >> a;
if (a < 1 && a >100)
{
cout << " Invalid number ! Try again ";
continue;
}
if (a >= 1 && a <=50)
{
c1 = c1 +1;
}
if ( a > 50 && a <= 100)
{
c2 = c2 +1;
}
}
cout << " There are << c1<< numbers in the interval [1, 50] ";
cout << "There are << c2 << numbers in the interval [51, 100] ";
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.