hi im a newbie her (forgive my poor english) i have an assignment to vreat a simple calculator that lets a user input 2 separate numbers and perform any chosen operation...
#include <iostream>
using namespace std;
int main()
{
int ichi, ni;
int a, b, c, d;
int sum, subs, m;
float qout;
int ans=ans;
labelA:
cout<<"Boss please enter the first Value: ";
cin>>ichi;
cout<<"\n";
cout<<"Boss please enter the second value: ";
cin>>ni;
cout<<"\n";
cout<<"Please select what operation you're going to use \n";
cout<<"#################################\n";
cout<<"a---Addition \n"<<"b---Subtraction \n"<<"c---Multiplication \n"<<"d---Division \n";
cout<<"#################################\n";
cin>>ans;
if(ans==a);
{
cout<<"The sum of the 2 numbers you have given is: "<<ichi+ni<<"\n";
goto labelA;
}
if(ans==b);
{
cout<<"The Difference of the 2 numbers you have given is "<<ichi-ni<<"\n";
goto labelA;
}
return 0;
}
i havent done the division and multiplication yet since i have encounter a problem on "if" the program only reads the if==a it wont read the if==b which is on subtraction part, and on the output it keeps on looping endlessly uncontrollable like crazy spamming >.< im lost please help.
well, I suggest you should first try and write the program without using goto since it is very dangerous. But the main problem is after all your if statements you have semicolons. Get rid of those.
The second problem is that you are trying to compare against integer values which have not been initialized. Try changing ans to type char and comparing the input against a character, like this: if (ans == 'a')
int main()
{
int ichi, ni;
char ans;
cout<<"Boss please enter the first Value: ";
cin>>ichi;
cout<<"\n";
cout<<"Boss please enter the second value: ";
cin>>ni;
cout<<"\n";
cout<<"Please select what operation you're going to use \n";
cout<<"#################################\n";
cout<<"a---Addition \n"<<"b---Subtraction \n"<<"c---Multiplication \n"<<"d---Division \n";
cout<<"#################################\n";
cin>>ans;
switch(ans){
case 'a':cout<<"The sum of the 2 numbers you have given is: "<<ichi+ni<<"\n";
break;
case 'b':
cout<<"The Difference of the 2 numbers you have given is "<<ichi-ni<<"\n";
break;
case 'c':
cout<<"The Multiplication of the 2 numbers you have given is "<<ichi*ni<<"\n";
break;
case 'd':
cout<<"The Difference of the 2 numbers you have given is "<<ichi/ni<<"\n";
break;
}