In: Computer Science
make a calculator in C++ or C language that can take up to 5 values at same time
Answer:
#include <iostream>
using namespace std;
int main()
{
char op;
float num1, num2,num3,num4,num5;
cout << "Enter operator either + or - or * or /: ";
cin >> op;
cout << "Enter five operands: ";
cin >> num1 >> num2 >> num3 >> num4
>> num5;
switch(op)
{
case '+':
cout << num1+num2+num3+num4+num5;
break;
case '-':
cout << num1-num2-num3-num4-num5;
break;
case '*':
cout << num1*num2*num3*num4*num5;
break;
case '/':
cout << num1/num2/num3/num4/num5;
break;
default:
// If the operator is other than +, -, * or /, error message is
shown
cout << "Error! operator is not correct";
break;
}
return 0;
}
Explanation:
First user type the operator and then operands. Here we use the switch statements where we given the different cases according to the operator.