First off, I'd like to say, definitely a fan of the use of goto. I love it, although it's evil.
If you truly want the user to select add or subtract, you're going to want to make them strings. Same with answer. Also yeah, string.h(<string> works too) is necessary for using strings.
Lets say the user input's add:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
if (answer[0]=='a') && (answer[1]=='d') && (answer[2]=='d') {
long double value1;
long double value2;
long double output1;
cout<<"Enter first number for addition. \n";
cin>>value1;
cout<<"Enter second number for addition. \n";
cin>>value2;
output1=value1+value2;
cout<<"The sum of these two numbers are: "<<output1;
goto labelA;
}
|
It'll compare the first character in answer to the character 'a', then 'd', and 'd' again. Same thing goes for sub.
EDIT: If you want, add an else statement, incase they misspell add, the else will pick it up and could say "Invalid, try again". Then goto start; (Where start: will be somewhere above where it asks to input add or sub.)
Don't get too much into the habit of goto's though. Didn't notice where LabelA: was.
Second off, you want to use the namespace std. so under your #includes type
using namespace std;
This way you won't have to type std::cout and std::cin over and over again, you can just type cout, and cin. (Since you're already using cout and cin, you need it)
PS: After you go to LabelA, ask if the user is done. And add a loop over everything so if he's not done, he can type add or sub again. Didn't notice where LabelA: was.
EDIT2: I'm 98% sure you don't need
1 2
|
#include<math.h>
#include<stdio.h>
|
EDIT3: You never tell the user that "done" ends the program. Probably should.
Also, what happens if the user types something that isn't add/sub/done?