Question: I write a program in c++ but i have only one issue that is i created a menu in which user have 3 choices 1

I write a program in c++ but i have only one issue that is i created a menu in which user have 3 choices 1 2 3 in numeric but suppose user entered any character then i use break statement which exit the prorgam but i want some changes in it such that if user entered character it display "Enter correct digit" and go to menu again with using loops can you do that by using my code

#include

#include

using namespace std;

int main ()

{

for(int q=1; ; q++)

{

cout<<"1. For Sum of nth term of series";

cout<

cout<<"2. For Design the Pattern ";

cout<

cout<<"3. For Exit ";

cout<

cout<<"************";

cout<

int choice,opt;

cout<<"Enter choice";

cin>>choice;

// Incorrect entry

if ((choice!=1)||(choice!=2)||(choice!=3))

{

cout<<"Enter correct option";

break;

}

// Menu 1

else if(choice==1)

{

int n,sum=0;

for (int i=1 ; ; i++)

{

cout<<" Enter nth term to find their sum : ";

cin>>n;

int next=2;

int k=1;

for (int i=1; i<=n; i++)

{

if (i!=n)

{

k=i*next;

cout<<"1/"<

}

else if (i==n)

{

k=i*next;

cout<<"1/"<

}

sum=sum+k;

}

cout<<"1/"<

}

}

// Menu 2

else if (choice==2)

{

int row;

cout<<"Enter the number of rows : ";

cin>>row;

for(int i = 1; i <= row; i++)

{

for(int space = 0; space <= row - i; space++)

{

cout<<" ";

}

for(int j = i; j >0 ; j--)

{

cout<

}

for(int j=2; j<=i; j++)

{

cout<

}

cout<<" ";

}

break;

}

//Menu 3

else if (choice==3)

{

cout<<" You are about to exit ";

cout<

break;

}

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!