Asked by mozart
1. Write an if-statement that increases the variable num1 by one and reduces the variable num2 by 1, if the variables are not equal.
MY ANSWER:
int num1 = 11;
int num2 = 10;
int counter = 1;
If (num1 != num2)
{
Num2+ counter
}
If (num2 != num1)
{
Num1 - counter
}
IS IT CORRECT? can someone help.
Thanks
MY ANSWER:
int num1 = 11;
int num2 = 10;
int counter = 1;
If (num1 != num2)
{
Num2+ counter
}
If (num2 != num1)
{
Num1 - counter
}
IS IT CORRECT? can someone help.
Thanks
Answers
Answered by
oobleck
why two checks? If they are not equal, do both changes.
The way you have it, changing Num2 might make them equal, and the 2nd check will fail. In fact, the way you have initialized the variables, the 2nd check will definitely fail!
The way you have it, changing Num2 might make them equal, and the 2nd check will fail. In fact, the way you have initialized the variables, the 2nd check will definitely fail!
There are no AI answers yet. The ability to request AI answers is coming soon!
Submit Your Answer
We prioritize human answers over AI answers.
If you are human, and you can answer this question, please submit your answer.