In: Computer Science
write this program in C++
Write a program that prompts a user for three characters. The program must make sure that the input is a number 10 - 100 inclusive. The program must re prompt the user until a correct input is entered. Finally output the largest and the lowest value.
Example 1:
Input : 10
Input : 20
Input : 30
The largest is 30.
The lowest is 10.
Example 2:
Input : 100
Input : 50
Input : 10
The largest is 100.
The lowest is 10.
Example 3:
Input : 1
Try again !
Input : 5
Try again!
Input : 30
Input : 80
Input : 200
Try again !
Input : 300
Try again!
Input : 80
The largest is 80
The lowest is 30
ANSWER: Here I am giving you the code and output please like it.
CODE:
#include <iostream>
using namespace std;
int main()
{
int a, b, c,larg,smll, count1=0,count2=0,count3=0;
while(1){
if(count1==0)
cin>>a;
if(a<10 || a>100){
cout<<"Try again !\n";
cin>>a;
count1++;
}else{
break;
}
}
while(1){
if(count2==0)
cin>>b;
if(b<10 || b>100){
cout<<"Try again !\n";
cin>>b;
count2++;
}else{
break;
}
}
while(1){
if(count3==0)
cin>>c;
if(c<10 || c>100){
cout<<"Try again !\n";
cin>>c;
count3++;
}else{
break;
}
}
if(a>b && a>c)
larg=a;
else if(b>a && b>c)
larg=b;
else
larg=c;
if(a<b && a<c)
smll=a;
else if(b<a && b<c)
smll=b;
else
smll=c;
cout<<"The largest is "<<larg<<endl;
cout<<"The lowest is "<<smll;
return 0;
}
OUTPUT: