178k views
0 votes
Write a main method that prompts the user for an integer between 1 & 20 (inclusive). If the user enters an invalid number, prompt for another one. When a valid number is entered, call activity with that number as a parameter.

User Wdziemia
by
5.1k points

1 Answer

2 votes

Answer:

int main() {

int num;

cout<<"Enter the number"<<endl;

cin>>num;

if(num<1 || num>20)

{

while(num>20 || num<1)//taking input if the number is not within range..

{

cout<<"Enter the number again"<<endl;

cin>>num;

}

activity(num);//calling activity with the num..

}

return 0;

}

Step-by-step explanation:

Above written is the main function in which a prompting an integer between 1 and 20 if it is not within range then again taking input.Then after that calling activity with num as argument.

User Cat Perry
by
4.6k points