0

Every if statement activates

https://code.sololearn.com/cofrv27a3p6W/?ref=app Alright guys. So I have this calculator here. Instructions are at the top. When ever I type in any assortment of numbers, like 1 1 (I haven't set up scaler yet for 3rd number) it ends up playong every single if statement. There are no return 0; because if you do that it stops the entire system at the return, and if you add else statements it glitches and says "else statement has no if statement". So this set up is the only way as far as I can tell that the code will work. But how even if the input is correct do I fix this problem? After all these error checks will be the main code which will have to have cleared and perfect numbers to work. Please help.

15th Aug 2018, 10:51 PM
Slushie
Slushie - avatar
5 Antworten
0
You need to use curly braces after the if statement like this... if (x == 5) { cout << "blah blah"; } if (x != 5) { cout << "blah blah"; } NOT this.. if (x == 5) { cout << "blah blah"; if (x != 5) { cout << "blah blah"; } }
16th Aug 2018, 1:47 AM
Dominic Nicholas
Dominic Nicholas - avatar
+ 2
Didn't quite test the logic, but one thing that's wrong with your code is that there is a semicolon before the body of each if statement, after the expression-checking closing bracket (I haven't written any c++ if you can't tell by my terminology) Line 27: this shouldn't be here V if (multipleOne >= 10 && multipleTwo >= 10); { cout << "-Sorry, but both of your input values of " << multipleOne << " and " << multipleTwo << " are too large. Try again. *Remember to keep input values below 10*" << endl; } See lines 31, 34, 36, and the rest of the if statements
15th Aug 2018, 11:23 PM
Just A Rather Ridiculously Long Username
0
Like is there a way I can fix the else if problem at all? Or am I just not thinking right?
15th Aug 2018, 10:53 PM
Slushie
Slushie - avatar
0
Alright so that fixed the problem. But now when I type in something that applys to an if statement other than the first, it doesn't work. like if you type 10 10 or 11 10, etc. the logic works. anything else like 10 1 or 0 0, -1 10, any other logic it says no output. (Anything that does work also says no output because I haven't set that up yet.)
15th Aug 2018, 11:35 PM
Slushie
Slushie - avatar
0
Ok thanks. I just finished all of the errors and that helped a lot.
16th Aug 2018, 3:31 AM
Slushie
Slushie - avatar