code:

Can't Copy and Paste this?

Click here for a copy-and-paste friendly version of this code!

 

Terms of Agreement:   

By using this code, you agree to the following terms...   

1) You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for langauges that allow it) freely and with no charge.   

2) You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   

3) You may link to this code from another website, but ONLY if it is not wrapped in a frame. 

4) You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.  

//     

/*

Author: Wilton Marranzini

Objective: this program is a four function calculator.

*/

#include  //including Lib.

//starting main

int main()

    {

     float answer = 0;//answer variable.

    float first_num = 0;//variable for the first input

    float second_num = 0;//variable for the second input

    char symbol;//the function symbol variable

    int again; //variable to repeat

    again=1;//making variable again = 1

    //starting while loop

    while (again==1)

        {

        cout<<"This is the four function calculator program.\n";

         cout<<"Enter the first number.\n";

        cin>>first_num; //first input

        cout<<"Enter the second number.\n";

        cin>>second_num;//second input

        cout<<"Enter the function you would like to perform.\n(+,-,*, or /)"

          <<"add, substract, multiply, divide, respective\n";

        cin>>symbol;//symbol input

        //starting case switch

         switch (symbol)

            {

            case '+':

             answer = first_num + second_num; //computing

            cout <<"Your answer is: "<

            break;

            case '-':

             answer = first_num-second_num;//computing

            cout <<"Your answer is: "<

             break;

            case '*':

             answer= first_num * second_num; //computing

            cout <<"Your answer is: "<

            break;

            case '/':

             if (second_num == 0) //checks if dividing by zero

                 {

                 cout<<"Attempting to divide by zero. SORRY, can't do it.\n";

            }

            else

                 {

                 answer = first_num/second_num;//computing

                cout <<"Your answer is: "<

            }

            break;

            default://checks if invalid character

             cout<<"Invalid operation character\n";

        }

        cout<<"would you like to perform, another calculation?\n";

        cout<<"1:YES2:NO\n";

        cin>>again;

    }

}