In: Computer Science
Integer value calculator: Write a program using C++ that acts as a calculator. The program should ask the user for two numbers and an operator. Then the program must print the result using the two input values and the operator.
Prompts and input requirements. Ask the user for two integer values and a value that indicates the operation. Likely you will want to choose the normal operators: + - * / %.
Output Requirements: Make your output easy to understand, both in the prompts and when printing the result.
Input Validation. The program should validate all input from the user and print an error message if the input is not valid. The integer values must be between -30,000 and + 30,000 and the operators must be one of these: + - * / %. If the input is not valid, the program should exit without printing a result.
Plss give like if u like my answer and any doubt free to ask.
#include<iostream>
using namespace std;
int main()
{
int num1,num2; //Take two integer variable for storing two numbers.
char op; //Take a character variable for storing operator.
cout<<"Enter two numbers:";
cin>>num1>>num2; //Taking user input for two number.
cout<<"Enter Operator:";
cin>>op;//Taking user input for operator.
if(num1=>-30000 && num1<=30000 && num2=>-30000 && num2<=30000 && op=='-'|| op=='+'||op=='*' ||op=='/')//inside if taking conditions as you given in question
{
switch(op)//use switch case for doing operation.
{
case '+':
cout<<"Addition of these two numbers:"<<num1+num2;
break;
case '-':
cout<<"Subtraction of these two numbers:"<<num1-num2;
break;
case '*':
cout<<"Multiplication of these two numbers:"<<num1*num2;
break;
case '/':
cout<<"Division of these two numbers:"<<num1/num2; //if u want division in points like 0.764 then u have to take num1 and num2 as float.
break;
default:
break;
}
}
else
{
cout<<"The integer values must between -30000 and +30000and the operator must be one of these:+-/*."; //For error.
}
return 0;
}