i was working on a simple calculator and here's the problem I'm having:
i want the whole program to loop over and over until the user decides to stop, so i put a while in there and the loop works great, but when the user is done inputting the numbers there is no pause between it showing the result and the loop starting back up again, so i put a "press any key to continue" command in there, well that's not working. so i was wondering if anyone could tell me how I'm doing it wrong and how to do it right.
Here's the code:
#include <iostream>
#include <cmath>
using namespace std;
int choice;
int result;
int num1;
int num2;
void add();
void sub();
void multi();
void divi();
int main() {
do{
system ("cls");
cout << "Do you want to: " << endl;
cout << "1. Add." << endl;
cout << "2. Subtract." << endl;
cout << "3, Multiply." << endl;
cout << "4. Divide." << endl;
cout << "5. Exit." << endl;
cin >> choice;
if (choice == 1){
add();
}
else if (choice == 2){
sub();
}
else if (choice == 3){
multi();
}
else if (choice == 4){
divi();
}
else {
cout << "That is not a choice." << endl;
}
}
while (choice != 5);
cin.get();
}
void add(){
system ("cls");
cout << "Enter the first number. " << endl;
cin >> num1;
cout << "Enter the second number. " << endl;
cin >> num2;
result = num1 + num2;
cout << "The total of " << num1 << " Plus " << num2 << " is " << result << endl << endl;
cout << "Press any key to continue." << endl;
cin.get();
}
void sub(){
system ("cls");
cout << "Enter the first number. " << endl;
cin >> num1;
cout << "Enter the second number. " << endl;
cin >> num2;
result = num1 - num2;
cout << "The total of " << num1 << " Minus " << num2 << " is " << result << endl << endl;
cout << "Press any key to continue." << endl;
cin.get();
}
void multi(){
system ("cls");
cout << "Enter the first number. " << endl;
cin >> num1;
cout << "Enter the second number. " << endl;
cin >> num2;
result = num1 * num2;
cout << "The total of " << num1 << " Multiplied by " << num2 << " is " << result << endl << endl;
cout << "Press any key to continue." << endl;
cin.get();
}
void divi(){
system ("cls");
cout << "Enter the first number. " << endl;
cin >> num1;
cout << "Enter the second number. " << endl;
cin >> num2;
result = num1 / num2;
cout << "The total of " << num1 << " Divided By " << num2 << " is " << result << endl << endl;
cout << "Press any key to continue." << endl;
cin.get();
}