Answer to Question #266796 in C++ for Nor

Question #266796

Make a simple calculator using switch statement. Use 4 mathematical operations in


mathematics.


a. When you type A in the console, it will add two numbers


1


st number: 198


2


nd number: 196


b. When you type S, it will subtract two numbers.


1


st number: 145


2


nd number: 67


c. When you type D, it will divide two numbers.


1


st number: 256


2


nd number: 8


d. When you type M, it will multiply two numbers.


1


st number: 125


2


nd number: 5

1
Expert's answer
2021-11-16T18:37:49-0500
#include <iostream>


using namespace std;


char s;
int a, b;


int main()
{
     cin >> s >> a >> b;
     switch (s)
     {
     case 'A':
          cout << a+b << '\n';
          break;
     case 'S':
          cout << a-b << '\n';
          break;
     case 'D':
          cout << a/b << '\n';
          break;
     case 'M':
          cout << a*b << '\n';
          break;


     default:
          break;
     }
  
  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