C++ Programming ( Simple Calculator Code)♦♦♦♦

in #programming7 years ago (edited)

// SImple Calculater

 #include <iostream.h>
 using namespace std;
  int main()
  {
system ("color f9");

    double num, den, result; //declear funcatin

       char op; // declear the opreaters "+,_,*,/"
     do{ // mean that loop working when 
     cout<< "\n\t\tEnter the Number"<<endl;// User disply show 
       cin>> num; // user input
       cout<<"\n\t\tEnter opreater +.-,*,/:"<<endl;//user disply show
        cin>>op; // user input
          cout<< "\n\t\tEnter the Second Number"<<endl; //user disply show
     cin>>den;// user input
    // Now when user want addation/multipaction/subtaractin/dividing user press the 
    //button "+,*,-,/"so result show input number then opreater
        if(op=='+')result=num+den;
         if(op=='-')result=num-den;
           if(op=='*')result=num*den;
         if(op=='/')result=num/den;
        // Here any opreation work display screen result
          cout << result << endl;
    
       }// while 
         while (op!='e');
       return 0;
       }
Sort:  

To expand on your idea you might have to look at operator precedence and introduce a virtual stack to handle the operands and operators.

Ive used the reverse polish notation to handle converting infix to postfix for a similar calc/eval project in assembler. Using RPN allows you to specify other custom operators, like functions for string handling: concatenation, uppercase, stringtoval and logical operations and even possible including bitwise operations.

Wikipedia has a good entry on RPN using infix to postfix, and a breakdown of the steps that are used to calculate some examples: https://en.wikipedia.org/wiki/Reverse_Polish_notation

Keep up the good work

Hi @faheemahmad
I want to learn HTML, CSS, Javascript and then Java, C++ and all the languages that can help me become an android and IOS developer. Do you have any good website in mind where I can learn all these languages?
I have an accounting background but said bye bye to it, do you think a person like me can learn all these languages without having any IT degree?

Coin Marketplace

STEEM 0.28
TRX 0.11
JST 0.031
BTC 68737.86
ETH 3840.56
USDT 1.00
SBD 3.62