Trouble with functions

int Addition(int a, int b); {
cout << "Enter your two numbers" << endl;
cin >> a;
cin >> b;
cout << "Calculating. . ." << endl;
c = a + b;
cout << "Result: " << c << endl;
system("pause");
return 0;
}

So basically I'm trying to make this function work for something and when I run it in the if statement it skips the cin >> parts and just shows the cout << parts.
console output: Calculating. . .
Result: -1.85119e+62
Press any key to continue . . .

if statement: if (choose == "Addition")
{
Addition;
}

Assistance will be greatly appreciated. :)
Last edited on
1) Please use code tags to make your code readable:

http://www.cplusplus.com/articles/z13hAqkS/

2)

Addition;

That's not how you call a function.
Last edited on
ok so i added the correct function call Addition(); but it gives me an error saying too few arguments in function call. what arguments would i put then?
The ones you've defined the function to take:

int Addition(int a, int b)

Also, in that line:

int Addition(int a, int b); {
the semicolon shouldn't be there. I'm surprised your compiler isn't giving you warnings or errors about that.
1
2
3
4
if (choose == "Addition")
	{
		Addition(int a, int b)
	}


that's what I did now but now there is an error under int a that says : type name not allowed
Last edited on
That's still not how you call a function. Perhaps you need to go back to your textbook and reread that section?
also for the bottom curly bracket there is a weird error saying: expected a ';'
Could you please help me with calling it? I'm really not sure I thought this was the right way.
also for the bottom curly bracket there is a weird error saying: expected a ';'

Would it surprise you to know that you're missing a ';' ?

Could you please help me with calling it? I'm really not sure I thought this was the right way.

What can I tell you that your textbook can't?

Seriously, this is absolutely fundamental stuff for C and C++ development. You can't get away with not learning it, so you might as well do it properly.
Last edited on
Would it surprise you to know that you're missing a ';' ? You told me to remove it
int Addition(int a, int b); {
There are lots of examples in the tutorial pages:
http://www.cplusplus.com/doc/tutorial/functions/

The very first example happens to be an addition function.
Thank you both for your time, I figured it out now.
You're welcome - glad it's all working now!
Topic archived. No new replies allowed.