Find error plzzz...

FInd Error plz....when we ask user whether he wanna continue or not he enters y but program ends but according to code it should bounce back to code....Problem is given below

TASK:Math tutor
write a program so it displays a
menu allowing the user to select an addition, subtraction, multiplication, or division
problem. The final selection on the menu should let the user quit the program. After
the user has finished the math problem, the program should display the menu again.
This process is repeated until the user chooses to quit the program.
Input Validation: If the user selects an item not on the menu, display an error message
and display the menu again.






#include<iostream>
using namespace std;
int main()
{
int choice;
double a,b,sum,product,division,sub;
char again;
do
{
cout<<"this program helps you in calculation ; "<<endl;
cout<<"1. Addition"<<endl;
cout<<"2. Subtraction"<<endl;
cout<<"3. Multiplication"<<endl;
cout<<"4. Division"<<endl;
cout<<"5. Quit the program "<<endl;
cout<<"enter your choice : "<<endl;
cin>>choice;
switch(choice)
{

if(choice<1|| choice>4)
{
cout<<"Enter only 1,2,3 or 4 " <<endl;
cout<<"selection menu is given below"<<endl;
cout<<"1. Addition"<<endl;
cout<<"2. Subtraction"<<endl;
cout<<"3. Multiplication"<<endl;
cout<<"4. Division"<<endl;
cout<<"5. Quit the program "<<endl;
}
else
{
case 1:
cout<<"enter first number : "<<endl;
cin>>a;
cout<<"enter second number : "<<endl;
cin>>b;
sum=a+b;
cout<<"sum of"<<a<<" and "<<b<<"is :"<<sum<<endl;
break;

case 2:
cout<<"enter first number : "<<endl;
cin>>a;
cout<<"enter second number : "<<endl;
cin>>b;
sub=a-b;
cout<<"difference of"<<a<<" and "<<b<<"is :"<<sub<<endl;
break;

case 3:
cout<<"enter first number : "<<endl;
cin>>a;
cout<<"enter second number : "<<endl;
cin>>b;
product=a*b;
cout<<"product of"<<a<<" and "<<b<<"is :"<<product<<endl;
break;

case 4:
cout<<"enter first number : "<<endl;
cin>>a;
cout<<"enter second number : "<<endl;
cin>>b;
division=a/b;
cout<<"division of"<<a<<" and "<<b<<"is :"<<division<<endl;
break;

case 5:
cout<<"Program Ending : ";
break;
}
}
cout<<"do you want to continue? "<<endl;
cin>>again;
}while(again=='Y'|| again=='y ');//error occurs here when user enters y it sshould go to start but it is ended.
return 0;
}
Last edited on
1. Use indents
2. Use code-wrapper [code][ /code]
3. Point out where the error happens
'y '
speacial thanks to "LowestOne" and as well as "TheDestroyer"
code realllllllllyyyyyyyyyyyyy worked
Last edited on
Topic archived. No new replies allowed.