Below is the code, the task is that the command, for example, exit , the console is closed and nothing else. "Pampered" with a calculator, tired, decided to exit the console, closing it with the phrase exit . Help me to do this, please, I tried to portray it through a while , but the command does not work:

 #include <iostream> #include <stdio.h> #include <cstdlib> #include <locale> #include <math.h> using namespace std; int main() { setlocale(LC_ALL, "RUSSIAN"); char o; do { cout << "Выполните действие" << endl; float x, y, z; char q; cin >> x; cin >> q; cin >> y; switch (q) { case '^': z = pow(x, y); break; case '+': (z = x + y); break; case '-': (z = x - y); break; case '/': (z = x / y); break; case '*': (z = x * y); break; } cout << (z) << endl; cin >> o; } while (o != 'exit'); system("pause"); return 0; } 

    1 answer 1

    1) if you want to enter "exit", then the variable o must be a string, not a char

    2) after reading cin >> o; add check

     if(o == "exit") exit(0);