-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalculator.cpp
More file actions
34 lines (31 loc) · 931 Bytes
/
Copy pathcalculator.cpp
File metadata and controls
34 lines (31 loc) · 931 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <iostream> // needed for std::cout and std::cin
using std::cout, std::cin; // better than doing "using namespace std;"
int main(){
cout << "**************************\n";
cout << "A SIMPLE CALCULATOR IN C++\n";
cout << "ENTER INPUT WITHOUT SPACES\n";
cout << "**************************\n\n\n";
while(true){
cout << "Enter an operation (+, -, *, /) | 'q' to quit: ";
char option;
cin >> option; // get char input
if(option == 'q' || option == 'Q') break;
double num1, num2, total;
cout << "Enter number 1 (double): ";
cin >> num1;
cout << "Enter number 2 (double): ";
cin >> num2;
switch(option){
case '+': total = num1 + num2;
break;
case '-': total = num1 - num2;
break;
case '*': total = num1 * num2;
break;
case '/': total = num1 / num2;
break;
}
cout << "The result is " << total << "\n";
}
return 0;
}