Hey im new on this forum and tried to code a little calculater but the compiler gives me the error "expected unqualified-id before 'switch'"
The code:
int zahl2 = zahl1;
int operation;
int main() {
cout << "Geben sie eine Zahl ein!" << endl;
cin >> zahl1;
cout << "Geben sie erneut eine Zahl ein!" << endl;
cin >> zahl2;
cout << "Mit was wollen sie rechnen +, -, *, /" << endl;
cin >> operation;
}
Firstly, your switch is outside of main so won't do anything even if it compiles. Secondly, you have to put quotes around something for it to be interpreted as a char by the compiler (i.e. '-' not - and '+' not +).
Here, I had to edit the code quite a bit, because there were multiple errors.
Like shadowmouse said, your "switch" was outside of any function, so it doesn't have any effect. Also int zahl2 = zahl1; I don't know what you tried to do here. I think you tried to declare two integers? The way to do that is: int zahl1, zahl2;.
And yes, in your case statements you must put the operations (+, -, *, /) in single quotes so they can be interpreted as a char.
Also it's better to use double or float in this situation, since if you input (3 / 4) the result will be 0.