Without curly braces "if" executes only on statement
1 2 3
if (operation=="*")
num[2] = num[0] * num[1]; //this statement is executed only if condition is true
cout << "The answer is: " << num[0] << " X " << " = " << num[1]; // this one is always executed
This will work (don't forget to do the same for all other 'else if' statements)
1 2 3 4 5 6
if (operation=="*")
{
num[2] = num[0] * num[1];
cout << "The answer is: " << num[0] << " X " << " = " << num[1];
}
a) switch is not guaranteed to have a performance boost over if/else if/else
b) there is nothing wrong with if/else if/else
c) switch cant take strings without a hack
d) as to your problem op, we aren't writing python code. unless you only have one statement directly after the if/else if/else/while/do-while/for, then you need {} around the statements