I'm trying to make a calculator in which user can use it until a wrong key is given by user. After result when i press y to start the process again it start showing all the code in cmd and keeps continue. please help me how to stop the process so i can give values again.
#include<iostream>
usingnamespace std;
int main()
{
int a;
int b;
int c;
int y;
char c1;
char c2;
char c3;
char c4;
start:
cout<<"Enter The First Value"<<endl;
cin>>a;
cout<<"Enter The Second Value"<<endl;
cin>>b;
cout<<"Enter 1 to Add"<<endl;
cout<<"Enter 2 to Subtract"<<endl;
cout<<"Enter 3 to Multiply"<<endl;
cout<<"Enter 4 to Divide"<<endl;
cin>>c;
if(c==1)
{cout<<"The Sum Is: "<<a+b<<endl;}
elseif(c==2)
{cout<<"The Difference Is: "<<a-b<<endl;}
elseif(c==3)
{cout<<"The Multiplication Is: "<<a*b<<endl;}
elseif(c==4)
{cout<<"The Product Is: "<<a/b<<endl;}
else
{cout<<"Wrong Entry"<<endl;}
cout<<"If You Want To Continue Press Y"<<endl;
cin>>y;
if(y)
{goto start;}
elsereturn 0;
}
Well first, you haven't declared a variable called "c", so create char c; so the option system works. The other thing to do is to make the calculation part into a function, which would look like this:
http://www.cplusplus.com/forum/general/89535/ why making a second topic about the same thing?
Anyway, if you use a char to read the input for the operation to perform, its value will be equal to the ASCII code of the number http://www.cplusplus.com/doc/ascii/ shows that '1' == 0x31 == 49
So to check the input you must do if(c == '1') or if(c == 49). The first one is preferred for readability
However if c is an int, its value will be the actual number the user enters
If you use the approach softwaretime suggested, remember to declare y inside main