C Program that Simulate a Simple Calculator

Write a program that simulates a simple calculator. It reads two integers and a character. If the character is +, the sum is printed; if it is -, the difference is printed; if it is *, the product is printed; if it is a /, the quotient is printed; and if it is a %, the remainder is printed. Use a SWITCH statement.

Write a program that simulates a simple calculator. It reads two integers and a character. If the character is +, the sum is printed; if it is -, the difference is printed; if it is *, the product is printed; if it is a /, the quotient is printed; and if it is a %, the remainder is printed. Use a SWITCH statement.

Source Code:
#include<iostream.h>
#include<conio.h>
void main()
{
    int a,b,c;
    char ch;
    cout<<"Enter any two numbes=";
    cin>>a>>b;
    cout<<"Enter Your choice[+,-,/,*,%]:";
    cin>>ch;
    switch(ch)
    {
        case '+':
          c=a+b;
          break;
        case '-':
          if(a>b)
            c=a-b;
          else
            c=b-a;
          break;
        case '*':
          c=a*b;
          break;
        case '/':
          c=a/b;
        case '%':
          exit(0);
        default:
          cout<<"you have to type 1-5 otpion";
          exit(0);
    }
    cout<<c;
    getch();
}
Output:
Enter any two numbes=6
4
Enter Your choice[+,-,/,*,%]:+

10

You May Also Like...

Socialize with Us