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
1
Expert's answer
2013-01-24T07:35:33-0500
#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 the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS