In C++ Write a program that asks the user for a number between 1 and 30, then di
ID: 3575473 • Letter: I
Question
In C++
Write a program that asks the user for a number between 1 and 30, then displays the following message based on the table below. Note that you should only have one output per run (in the order of priority shown in the table). DO NOT WRITE A SEPARATE TEST FOR EACH NUMBER OR YOU WILL RECEIVE A ZERO! Examples: Please enter a number between 1 and 30: 2 Adam Please enter a number between 1 and 30: 3 Debbie Please enter a number between 1 and 30: 15 Charlie Please enter a number between 1 and 30: 1 No category!Explanation / Answer
#include<bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[])
{
int n;
int flag=1;
while(flag)
{cout<<"Enter number between 1 and 30:";
cin>>n;
if(n<1)
cout<<"Too slow ";
else if((n>=1&&n<=19)&&(n%2==0))
{
cout<<"Adam ";
}
else if((n>=18&&n<=30)||(n%2==0))
{
cout<<"Betty ";
}
else if((n>=9 && n<=22)||(n%2==0))
{
cout<<"Charlie ";
}
else if((n>=3 && n<=29)&& (n%2!=0))
{
cout<<"Debbie ";
}
else if(n>30)
{
cout<<"Too high ";
}
else
{
cout<<"No category ";
}
if(flag==0)
break;
}
return 0;
}
====================================================================
Output:
akshay@akshay-Inspiron-3537:~/Chegg$ ./a.out
Enter number between 1 and 30:2
Adam
Enter number between 1 and 30:3
Debbie
Enter number between 1 and 30:15
Charlie
Enter number between 1 and 30:1
No category