37.7k views
1 vote
Write a main method that prompts the user for an integer between 1 & 10 (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 Maher HTB
by
7.0k points

1 Answer

5 votes

Answer:

int main() {

int n;

cout<<"Enter the integer n"<<endl;

cin>>n;

if(n<1 || n>10)

{

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

{

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

cin>>n;

}

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

}

return 0;

}

Step-by-step explanation:

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

User Bruno Cunha
by
5.9k points