Calculator
Calculator
int main()
{
float x,y,r;
char operation;
cout << "Enter the First Number: " << endl;
cin>>x;
cout << "Enter the Second Number: " << endl;
cin>>y;
cout << "Select the Type of Operation: " << endl;
cout << "1. Addition : (+)"<< endl;
cout << "2. Subtraction : (-)"<< endl;
cout << "3. Multiplication : (*)"<< endl;
cout << "4. Division : (/)"<< endl;
cout << "Enter your choice (+,-,*,/): "<< endl;
cin>>operation;
switch (operation){
case '+':
r=x+y;
cout << "Result: " <<x<< " + " <<y<< " = " <<r<< endl;
break;
case '-':
r=x-y;
cout << "Result: " <<x<< " - " <<y<< " = " <<r<< endl;
break;
case '*':
r=x*y;
cout << "Result: " <<x<< " * " <<y<< " = " <<r<< endl;
break;
case'/':
if(y!=0){
r=x/y;
cout << "Result: " <<x<< " / " <<y<< " = " <<r<< endl;
}
else{
cout << "Error: Division by zero is not allowed ,Please Try again." << endl;
}
break;
default:
cout << "Error: Invalid operation selected." << endl;
break;
}
return 0;
}