Калкулатор

Да се въведат две числа и знак за операция между тях (+ – * /), да се пресметне и изведе резултатът от операцията.

Публикувано в 11в с етикети . Постоянна връзка.

4 коментара по Калкулатор

  1. kaloyan каза:
    #include <cstdlib>
    #include <iostream>
    
    using namespace std;
    
    int main(int argc, char *argv[])
    {
        int a,b;
        char ch;
        
        cout<<"Vavedete dve chisla: ";
        cin>>a>>b;
        cout<<"Vavedete aritmetichna operaciq: ";
        cin>>ch;
        
        switch (ch) {
            case '+' : cout<<a+b; break;
            case '-' : cout<<a-b; break;
            case '*' : cout<<a*b; break;
            case '/' : cout<<(double)a/b; break;
        default: cout<<"Nevalidna operaciq";
        }
        
        cout<<endl;
        
        system("PAUSE");
        return EXIT_SUCCESS;
    }
    
  2. sup3rEva каза:
    #include <cstdlib>
    #include <iostream>
    
    using namespace std;
    
    int main(int argc, char *argv[])
    { 
        int a,b;
        char znak;
        cout<<"Vyvedete chislo"<<endl;
        cin>>a;
        cout<<"Vyvedete chislo"<<endl;
        cin>>b;
        cout<<"Vyvedete znak"<<endl;
        cin>>znak;
        cout<<endl;
        switch  (znak){
              case '+': cout<<(a+b)<<endl; break;
              case '-': cout<<(a-b)<<endl; break;
              case '/': cout<<(a/b)<<endl; break; 
              case '*': cout<<(a*b)<<endl; break;
                   }   
      cout<<endl;
              
                    system("PAUSE");
        return EXIT_SUCCESS;
    }
        
  3. kaloyan каза:
    #include <cstdlib>
    #include <iostream>
     
    using namespace std;
     
    int main(int argc, char *argv[])
    {
        int a,b;
        char ch;
         
        cout<<"Vavedete dve chisla: ";
        cin>>a>>b;
        cout<<"Vavedete aritmetichna operaciq: ";
        cin>>ch;
         
        switch (ch) {
            case '+' : cout<<a<<"+"<<b<<"="<<a+b; break;
            case '-' : cout<<a<<"-"<<b<<"="<<a-b; break;
            case '*' : cout<<a<<"*"<<b<<"="<<a*b; break;
            case '/' : if (b!=0) cout<<a<<"/"<<b<<"="<<(double)a/b;
                       else cout<<"Na 0 ne se deli"; break;
        default: cout<<"Nevalidna operaciq";
        }
         
        cout<<endl;
         
        system("PAUSE");
        return EXIT_SUCCESS;
    }
    
  4. sup3rEva каза:
    #include <cstdlib>
    #include <iostream>
    
    using namespace std;
    
    int main(int argc, char *argv[])
    { 
        int a,b;
        char znak;
        cout<<"Vyvedete chislo"<<endl;
        cin>>a;
        cout<<"Vyvedete chislo"<<endl;
        cin>>b;
        cout<<"Vyvedete znak"<<endl;
        cin>>znak;
        cout<<endl;
        switch  (znak){
              case '+': cout<<(a+b)<<endl; break;
              case '-': cout<<(a-b)<<endl; break;
              case '/': if (b==0) cout<<"Na 0 ne se deli";
              else
              cout<<(a/b)<<endl; break; 
              case '*': cout<<(a*b)<<endl; break;
               default : cout<<"Nevalidna opperaciq"<<endl;    }   
      cout<<endl;
              
                    system("PAUSE");
        return EXIT_SUCCESS;
    }

Вашият коментар