on Leave a Comment

C++ Program to Make Simple Calculator

This c++ program performs operations of simple calculator. This c++ program performs addition, subtraction, multiplication and division operations using do-while loop and switch statement. 

C++ Program to Make Simple Calculator

#include<iostream>
#include<stdlib.h>
#include<conio.h>
using namespace std;
int main()
{
    float a, b, c;
    char ch;
    do
    {
        system("cls");
        cout<<"\n1. Addition";
        cout<<"\n2. Subtraction";
        cout<<"\n3. Multiplication";
        cout<<"\n4. Division";
        cout<<"\n5. Exit";
        cout<<"\n\nEnter your choice: ";
        int choice;
        cin>>choice;
        switch(choice)
        {
            case 1:
                cout<<"\n\nEnter two numbers: ";
                cin>>a>>b;
                c = a+b;
                cout<<"Sum of "<<a<<" and "<<b<<" is "<<c;
                break;
            case 2:
                cout<<"\n\nEnter two numbers: ";
                cin>>a>>b;
                c = a-b;
                cout<<"Difference between "<<a<<" and "<<b<<" is "<<c;
                break;
            case 3:
                cout<<"\n\nEnter two numbers: ";
                cin>>a>>b;
                c = a*b;
                cout<<"Product of "<<a<<" and "<<b<<" is "<<c;
                break;
            case 4:
                cout<<"\n\nEnter two numbers: ";
                cin>>a>>b;
                c = a/b;
                cout<<"Quotient is "<<c;
                break;
            case 5:
                exit (0);
            default:
                cout<<"\nYou have entered a wrong choice\nPlease try again";
        }
        cout<<"\n\nDo you want to continue (Y/N):";
        cin>>ch;
    }
    while(ch=='y' || ch=='Y');
    return 0;
}
  
OUTPUT: 


c++ program to make simple calculator
C++ Program to Make Simple Calculator

0 comments:

Post a Comment