Good day to everyone. Can someone lend me a hand in modifying the code below? We are needed to modify the code below by inserting a "PRESS ANY KEY TO CONTINUE below" in it as instructed by our teacher as our assignment. And when I press any key, It will somehow restart to "Enter an operator (+, -, *, /):"
I'm working on it for hours and I somehow can't successfully do it. Also, I need to point out that the system should stop printing the main menu for a moment unless a key should be printed first.
// Program to build a simple calculator using switch Statement
#include <iostream>
#include <conio.h>
using namespace std;
int main() {
char oper;
float num1, num2;
cout << "Enter an operator (+, -, *, /): ";
cin >> oper;
cout << "Enter two numbers: " << endl;
cin >> num1 >> num2;
switch (oper) {
case '+':
cout << num1 << " + " << num2 << " = " << num1 + num2;
break;
case '-':
cout << num1 << " - " << num2 << " = " << num1 - num2;
break;
case '*':
cout << num1 << " * " << num2 << " = " << num1 * num2;
break;
case '/':
cout << num1 << " / " << num2 << " = " << num1 / num2;
break;
default:
// operator is doesn't match any case constant (+, -, *, /)
cout << "Error! The operator is not correct";
break;
}
return 0;
}
Thanks for the help bro. I somehow can't successfully do it. Also, I need to point out that the system should stop printing the main menu for a moment unless a key should be printed first.
"PRESS ANY KEY TO CONTINUE below" in it as instructed by our teacher as our assignment. And when I press any key, It will somehow restart to "Enter an operator (+, -, *, /):"
If what I posted above isn't what is expected, then you need to more specific re the requirement.
It will display the 'menu', obtain the operation, then the 2 numbers as appropriate, then display the calculation, then display the Press Any Key message, and then re-display (re-start) the menu when any key is pressed.
I apologize for it, bro. It is my fault. I'll be more specific in questioning next time. Anyways. Thanks for the help. I somehow managed to figure out it on my own. That code gives me a reference and because of it I successfully did it.