Help with my prog.
Hi, I'm new to C++ and I've run into a fair few compile problems trying to make this fairly simple program work. I was wondering if one of you guys could run an experienced eye over it and show me my mistakes.
Code:
#include <iostream> |
Re: Help with my prog.
Quote:
Also with your switch statement earlier on, you don't need the '' in case '6' for example, you can just write: Code:
case 6: Code:
if ( calculateTotal > 0 ) Code:
calculateTotal(x, y) |
Thanks for the help but it still doesnt seem to want to run. I'm not upto speed with the language, would it be possible for you to give me an idiots guide to what I've got wrong.
|
Let's start with your function:
Code:
int calculateTotal( int a, int b ) Perhaps what you wanted to do is use the values you pass to the function (a and b) to perform the calculation and then return the result? If so, you would simply write Code:
int calculateTotal(int a, int b) |
Quote:
Code:
int calculateTotal(int a, int b) |
Whoops, let me edit my post. Edit: of course, it is unnecessary to use another variable; you could just perform the calculation in the return statement:
Code:
return (a*10 + (-5)*b); |
Heh, I see that you can use the single quotes with case. It compiles fine (as I said though, it isn't necessary to have them there. "case 6: " would do).
So, the next problem is your if statement. You want to check whether the value returned by your function, calculateTotal() is greater than zero. As I said, calculateTotal() is a function and you need to include the brackets. The function takes two arguments and doesn't have default values so you must pass values to it. In your case, you would write: Code:
if(calculateTotal(wins, lose) > 0) Code:
int money = calculateTotal(wins, lose); // store value returned by calculateTotal in money Edit: also, you can get rid of that "b = lose;" line. Edit again: in relation to said line, you haven't declared b to be an int in main(). The b in your calculateTotal() function is local to that function. |
Ok, it would probably have made more sence if I had told you what I was attempting.
Quote:
|
All times are GMT -5. The time now is 02:58 PM. |