Hi, I built a basic calculator that could use addition (or subtraction, etc, if I changed the code) but I wanted to build one that did addition, subtraction, multiplication and division depending on what the user wanted.
I've encountered a problem using the Else If Else statement. It seems not to read it and simply goes straight to ending the program. I've switched it around so many times and tried everything I can think of, but I'm obviously not getting it! Can somebody help?
op is a char so you are reading a single character into it. 1 is not the same as '1'. If you want op to be a char you can make the comparison like this op == '1'
Or you can change op to be an int and the it should work.
'op' is a char. When the user inputs 1 (the number), the program reads '1' (the character). The value of '1' is not 1 (it's 49 or something).
You can fix it either by changing the type of 'op' to int, or by replacing your conditionals to: if (op == '1') { ... }
The first option is easier; the second option is more generic (i.e. you can replace 1/2/3/4 with A/S/M/D or +/-/*// (okay bad choice of separator there, whatever)).
[edit] line 24 also has a double ';' at the end. Bad (but probably meaningless)!