Header Ads

Header ADS

Calculator proramm in c++ simple code

Calculator proramm in c++ simple code


Make a four function calculator. Read in two numbers and a mathematical operator. Add the two numbers if the operator ‘+’ is entered. Subtract the two numbers if operator ‘-‘is entered and so on. Display the calculated result. If any character other than +,-,*, /is entered, display proper error message.




                       Step1:    Start
                       Step2:    Declare num1,num2,
                       Step3:    Declare character ( + , - , * , / )
                       Step4:    Input num1 & num2
                       Step5:    Input sign like ( + , - , * , / )
                       Step6:    Display Calculation 
                       Step7:    End




# include <iostream>
using namespace std;

int main ()
{
            int num1,num2;
            char sign;
 cout<< "Enter 1st number="<<endl;
 cin>> num1;

 cout<<"Enter 2nd number="<<endl;
 cin>> num2;

 cout<< "Enter sign\n=";
 cin>>sign;
 if (sign=='+')
 {
             cout<<num1+num2<<endl;
 }
 else if (sign=='-')
 {
             cout<<num1-num2<<endl;
 }
 else if (sign=='*')
 {
             cout<< num1*num2<<endl;
 }
 else if (sign=='/')
 {
             cout<< num1/num2<<endl;
 }
 else
 {
             cout<<"You have enter an invalid sign"<<endl;
 }
 return 0;
}



flow chart of calculator C++














how to make calculator in c++





1 comment:

  1. The algebra section of the calculator should have the same capabilities. Imagine a design problems demands solving several algebraic fractions. To do this by hand is extremely time consuming and error prone and when one has many of these problems it becomes impossible to do. matrix calculator

    ReplyDelete

Powered by Blogger.