Answer to Question #3324 in C++ for mukunda

Question #3324
Write a program to print the desired output when you give an input as 1 to add, 2 to multiply, 3 to subtract using switch.
1
Expert's answer
2011-07-11T10:05:48-0400
#include <iostream>
using namespace std;

int main()
{
int num1 = 10, num2 = 23;

cout << "A = " << num1 << ", B = " << num2 << endl;
cout << "Please choose: 1(add), 2(multiply), 3(substract):" << endl;

int choice = -1;
cin >> choice;

int result = 0;
switch (choice) {
& case 1: result = num1 + num2; break;
& case 2: result = num1 * num2; break;
& case 3: result = num1 - num2; break;
}
cout << "Result is " << result << endl;
return 0;
}

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