Ask coding questions

← Back to all posts
expected expression error in c++
EricHofmann11 (0)

I am trying to create a program that will simply do calculations. However, when I try to prevent the user from inputting '\' instead of '/'. I get the error message "if (opsign == '\') expected expression ^

Comments
hotnewtop
SixBeeps (5056)

The backslash is used for escaping characters in most languages. If you want to enter a backslash character in a string, you have to escape it (effectively escaping the thing that's used for escaping):

printf("\\"); // This outputs one backslash
EricHofmann11 (0)

@SixBeeps could you please help me with my updated program? after I implemented your form of the forward slash, my next assignment was to use the same program, but with a switch statement. Once I did so, I started to get another error message saying multiple definitions of main.