Write a program and call it calc.cpp which is the basic calculator and receives three values from input via keyboard.C++ program to make simple calculator. To make a simple calculator in C++ Programming which performs basic four mathematics operation.how to make a simple calculator using switch,else if,conditional operator? ... Here is the code for simple calculator implemented using switch
#include <iostream>
using namespace std;
int main()
{
int number1;
int number2;
int sum;
int sub;
int max;
char choice;
cout << "enter number one\n";
cin >> number1;
cout << "enter number two\n";
cin >> number2;
cout << "\t\t\t\tPress (A) for addtion\n";
cout << "\t\t\t\tpress (S) for sub \n";
cout << "\t\t\t\tpress (M) for mux\n";
cin >> choice;
switch (choice)
{
case 'A':
sum = number1 + number2;
cout << "sum is"<<sum<<endl;
break;
case 'S':
sub = number1 - number2;
cout << "sub is " << sub << endl;
break;
case 'M':
max = number1*number2;
cout << "max is " << max<<endl;
break;
default:
cout << "please enter the number from 1 to 3\n";
break;
}
system("pause");
}
Sign up here with your email
ConversionConversion EmoticonEmoticon