### Why is the answer to every operation wrong?

This is my calculator project I've been working on. But, every time i try to get an answer, it's always wrong.

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113`` ``````#import using namespace std; double addition (double a, double b) { double z; z = a + b; return (z); } double subtraction (double a, double b) { double z; z = a - b; return (z); } double multiplication (double a, double b) { double z; z = a * b; return (z); } double division (double a, double b) { double z; z = a / b; return (z); } int main () { long double aa; long double ab; long double ac; char add; char sub; char mlp; char div; char a; char b; char c; char res; c = '\a'; b = '\0'; a = '\0'; res = 'r'; add = 'a'; sub = 's'; mlp = 'm'; div = 'd'; int_main: cout << "Please choose a mathematical method. (a/s/m/d): "; cout << endl; cin >> a; if (a == add) { ac = addition (aa,ab); cout << "You have chosen addition. Please provide a numerical value: "; cout << endl; cin >> aa; cout << "Please provide another numerical value: "; cout << endl; cin >> ab; cout << "Your result value is " << ac << "." << endl; goto int_main; } else if (a == sub) { ac = subtraction (aa,ab); cout << "You have chosen subtraction. Please provide a numerical value: "; cout << endl; cin >> aa; cout << "Please provide another numerical value: "; cout << endl; cin >> ab; cout << "Your result value is " << ac << "." << endl; goto int_main; } else if (a == mlp) { ac = multiplication (aa,ab); cout << "You have chosen multiplication. Please provide a numerical value:"; cout << endl; cin >> aa; cout << "Please provide another numerical value: "; cout << endl; cin >> ab; cout << "Your result value is " << ac << "." << endl; goto int_main; } else if (a == div) { ac = division (aa,ab); cout << "You have chosen division. Please provide a numerical value: "; cout << endl; cin >> aa; cout << "Please provide another numerical value: "; cout << endl; cin >> ab; cout << "Your result value is " << ac << "." << endl; goto int_main; } else { else_final: cout << "I'm sorry, but " << a << " is not a valid mathematical operation." << endl; cout << "Press/enter 'r' to restart." << endl; cout << "Press/enter any other character to quit." << endl; cin >> b; if (b == res) goto int_main; } return 0; }``````

Can anyone debug this and repost? Telling me what i did wrong would be good, too.
 But, every time i try to get an answer, it's always wrong.

A sample output compared to expected output would be helpful.

 ``12345678`` ``````ac = addition (aa,ab); cout << "You have chosen addition. Please provide a numerical value: "; cout << endl; cin >> aa; cout << "Please provide another numerical value: "; cout << endl; cin >> ab; cout << "Your result value is " << ac << "." << endl;``````

This is backwards, you call the function before you set values to aa and ab. Same thing for the rest of them, you always call the function before you assign values.

One thing that tripped me up a little bit was the variables, why do you have so many? `a == add` could be replaced with a comparison to a specific character (`if (/*char*/a == 'a') { //code and such} `).

 Can anyone debug this and repost?

It can be done, it's better if you apply the suggested fixes yousel...

 Telling me what i did wrong would be good, too.

I laughed so hard. Were you expecting someone to fix it and give it to you?
For starters You are calling all of your operation functions before you get their needed inputs. So the outputs you are getting will be whatever aa and ab are initialized to, which since you didn't specify it will be some random number...

also I might recommend using an enum type for your operation selection and simply a 1-4 selection menu.

That part would look like this:
 ``12345678910111213`` ``````int choice=1; enum Operation { ADD=1,SUB,MLP,DIV}; cout <<" Select Operation:\n" <<"1. Add\n" <<"2.Subtract\n" // you can complete it from here cin >> choice; switch(choice){ case ADD: // you addition set called here break; case SUB: // you subtraction set called here break; // etc. default: cout <<"Error has occured in selection"; break;``````

make sure to keep a break at the end of each case and to receive your variables before you call the function. But that should get you to the solution.
Just a healthy reminder:

Never use the goto statement.