I have this function that should add two numbers if thmethod is 'a'
tmethod is set to a before and cnr1 and cnr two are numbers.
I get a warning like this when i try to compile:
Possibly incorrect assignment in function calc(int,int,char)
Anyone know why?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
int calc(int cnr1, int cnr2, char tmethod)
{
if (tmethod == 'a')
calculation = cnr1 + cnr2;
return(calculation);
}
// this is how i call the function:
int int1, int2;
char method;
int ans;
int1 = 5;
int2 = 7;
method ='a';
ans = calc(int1, int2, method);
I would hazard a guess that 'a' represents 'addition', so if it did not equal a then a different thing would be called based on what tmethod is. Just a guess.
also
If yes: There is no need to return the value.
if it was called in that way there would be, beacuse then ans would = calculation
It would only not need to be returned if it was called like: