Q: How to make a calculator in C++?
#include <iostream>
using namespace std;
int main()
{
double number1, number2, total;
int current_operation;
cout << "Please Enter First Number: ";
cin >> number1;
cout << "Please Enter Second Number: ";
cin >> number2;
cout << "Which operation would you like use?\n" << endl;
cout << "Type 1 for Plus." << endl;
cout << "Type 2 for Minus." << endl;
cout << "Type 3 for Divide." << endl;
cout << "Type 4 for Multiply.\n" << endl;
cout << "Enter Number from above given Operations: ";
cin >> current_operation;
if(current_operation == 1)
{
total = number1 + number2;
cout << "Your Answer is = " << total << endl;
}
else if(current_operation == 2)
{
total = number1 - number2;
cout << "Your Answer is = " << total << endl;
}
else if(current_operation == 3)
{
total = number1 / number2;
cout << "Your Answer is = " << total << endl;
}
else if(current_operation == 4)
{
total = number1 * number2;
cout << "Your Answer is = " << total << endl;
}
else
cout << "You Have Entered an Invalid Number."<< endl;
return 0;
}