- 1
How to complete the simple calculator ?
It is a part of the learn codes
2 Answers
0
#include <iostream>
using namespace std;
//sample input//20*2,20+2,20Ă·2,20-2
int main() {
double var1; //Create variables
char oper;
double var2;
double total;
char answer;
cout << "Print first variable: "; //Set varriables
cin >> var1;
cout << "\nPrint operator:";
cin >> oper;
cout << "\nPrint second variable:";
cin >> var2;
switch (oper) {
case '+':
total = var1 + var2; //Cheak operators
break;
case '-':
total = var1 - var2;
break;
case '*':
total = var1 * var2;
break;
case '/':
total = var1 / var2;
break;
default:
cout << "\nYou must write +, -, * or /." << endl;
}
cout << "\nTotal: " << total << endl; //View total
return 0;
}
I just reprogram it and hope it helps