63 845
Assignments Done
99,2%
Successfully Done
In August 2018

Answer to Question #22809 in C++ for Sara

Question #22809
//write a program that enter two number and the sign and the output is sum or
subst or multi or divide according to sign hint (use switch )
Input : 1 + 2
Output :3
Input : 3 * 3
Output : 9 use switch
Expert's answer
#include <conio.h>
#include <iostream>

using namespace std;

void main()
{
int a, b;
char sign;
int result;

cout << "Enter an expression: ";
cin >> a >> sign >> b;

switch (sign)
{
case '+':
result = a + b;
break;

case '*':
result = a * b;
break;

case '-':
result = a - b;
break;

case '/':
result = a / b;
break;

default:
cout << "Invalid input." << endl;
getch();
return;
}

cout << "Result: " << result << endl;
getch();
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions