Results 1 to 6 of 6

Thread: C++ code for a simple calculator

  1. #1
    Level 3 alanmark's Avatar
    Join Date
    Apr 2013
    Location
    Cyber Space
    Posts
    392
    Thanks
    59
    Thanked 35 Times in 32 Posts

    C++ code for a simple calculator

    guys, just few mins before I was searching on internet for a simple C code to make a simple calculator to reply on the thread that Mehul has opened: http://offlinemarketingforum.com/c-c...success-c.html and found some codes of a simple calculator which can perform addition, subtraction, multiplication and division both on C and C++.

    I have shared C code over here: http://offlinemarketingforum.com/c-c...success-c.html and sharing C++ code below:


    Code:
    #include <iostream>
    
    using namespace std;
    
    //addition
     float addition( float num1, float num2)
    { return num1 + num2; }
    
    //subtraction
     float subtraction(float num1, float num2)
     {return num1-num2;}
    
    //multiplication
    float multiplication(float num1, float num2)
    {return num1*num2;}
    
    //division
    float division(float num1, float num2)
    {return num1/num2;}
    
    
    //main function
    int main()
    {
        float number1;
        float number2;
        int choice;
        cout<<"What would you like to do?(1=add, 2=subtract, 3=multiply, 4=divide)"<<endl;
        cout<<"Choice:"<<endl;
        cin>>choice;
        
        if(choice==1)
        {//addition
        cout<<"What is your first number?(addition)"<<endl<<"Number:";
        cin>>number1;
        cout<<"What would you like to add?"<<endl<<"Number:";
        cin>>number2;
        cout<<"Your Answer is:"<<addition(number1, number2)<<endl;}
       else
       if(choice==2)
        {//subtraction
        cout<<"What is your first number(subtraction)?"<<endl<<"Number:";
        cin>>number1;
        cout<<"What number would you like to subtract?"<<endl<<"Number:";
        cin>>number2;
        cout<<"Your Answer is:"<<subtraction(number1, number2)<<endl;}
      else
      if(choice==3)
        {//multiplication
        cout<<"What is your first number(Multiplication)?"<<endl<<"Number:";
        cin>>number1;
        cout<<"What number would you like to multiply?"<<endl<<"Number:";
        cin>>number2;
        cout<<"Your Answer is:"<<multiplication(number1, number2)<<endl;}
      else
        //division
        cout<<"What is your first number(Divide)?"<<endl<<"Number:";
        cin>>number1;
        cout<<"What number would you like to Divide by?"<<endl<<"Number:";
        cin>>number2;
        cout<<"Your Answer is:"<<division(number1, number2)<<endl;
        
        system("PAUSE");
        return 0;
    }
    Enjoy the simple code for making a simple calculator using C++.

  2. #2
    OMF Member
    Join Date
    May 2013
    Location
    Bangladesh
    Posts
    147
    Thanks
    10
    Thanked 8 Times in 8 Posts

    Re: C++ code for a simple calculator

    That is a quite large code for me. Don't you have any short code for C++?

  3. #3
    Level 3 alanmark's Avatar
    Join Date
    Apr 2013
    Location
    Cyber Space
    Posts
    392
    Thanks
    59
    Thanked 35 Times in 32 Posts

    Re: C++ code for a simple calculator

    Generally C++ codes are huge in size but they are more user friendly than conventional C codes. The code I have shared are very easy, you just go through the code attentively once, I am sure you will understand the code after reading once.

    Anyways I am searching on internet to find some more codes and also trying to write one by myself. I will share if I find more easy code over here.

  4. #4
    OMF Member
    Join Date
    Jul 2013
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: C++ code for a simple calculator

    hmm.... I'm like only a day into C++ programming... that code line looks way above my level..







    BacklinksVault
    Last edited by ananthapriya; 07-22-2013 at 12:00 AM.

  5. #5
    OMF Member
    Join Date
    Nov 2013
    Posts
    5
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: C++ code for a simple calculator

    How about making a scientific calculator?

  6. #6
    RED TORRENT MEDIA LLC
    Guillermo Mata's Avatar
    Join Date
    Mar 2013
    Location
    DALLAS, TX
    Posts
    348
    Blog Entries
    5
    Thanks
    83
    Thanked 54 Times in 39 Posts

    Re: C++ code for a simple calculator



    thats would be cool to see.
    Technical Support Staff:
    support@redtorrentmedia.com
    Business Inquiries:
    info@redtorrentmedia.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •