Function Problem?

null
Last edited on
It looks like you need pass isvalid as a reference in the times function. Also you should consider using an if/else instead of the two if statements.
1
2
3
4
if(z == x * y)
   isvalid = true;
else
  isvalid = false;
A few points:

times(x, y, z, isvalid);
You pass a copy of isvalid to the function which always will be true; you need to pass it as a pointer or reference if you want the function to change the value.

if (isvalid = true) You just assign true to the variable, comparision operator is ==

BTW. If you compile your code with all warnings on, the compiler should warn you.
null
Last edited on
And the error is?

It appears that you added an unnecessary ampersand in the function call.

Had this error:

Error C2664 : 'void times(int,int,int,bool &)': cannot convert argument 4 from 'bool *' to 'bool &' Line 62

but I fixed line 62 like you said by removing the ampersand.

However now when I run the program,
when I enter -1, it doesn't exit the program.
Last edited on
When I run your program it exits properly when I entered -1.

By properly I mean that it displayed the message "The answer is correct. Good Job!" then exited the program.

By the way your program will always display the above message, since you used the assignment operator instead of the comparison operator in the if() statement.
null
Last edited on
It now won't exit because z can never be -1 at the end of the while statement, it will always be the "correct" answer since that is the only way you can get past the inner loop.

Perhaps you should consider changing the inner while() statement to something like:

while (isvalid || z == -1)
Last edited on
Thanks for your help. I really appreciate you taking time out your day to help me.
Topic archived. No new replies allowed.