Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

What is the best long-run business practice?

Answered: 1 week ago

Question

LO 2-3 Differentiate between Exempt and Nonexempt Workers

Answered: 1 week ago

Question

c. What were you expected to do when you grew up?

Answered: 1 week ago

Question

d. How were you expected to contribute to family life?

Answered: 1 week ago

Question

e. What do you know about your ethnic background?

Answered: 1 week ago