AlexRapso commented on a Page, Simple Calculator  -  Apr 23, 2010

I got bored and fixed it :x

#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

void instructUser()
{
        cout << "                    " <<endl;
        cout << "  ***************************************************************************" <<endl;
        cout << "  *  This program takes your input and selected mathematical operator       *" <<endl;
        cout << "  *  and returns the answer to the screen. If an illegal operator is        *" << endl;
        cout << "  *  selected, an error message will be displayed. Be careful which         *" <<endl;
        cout << "  *  operator you select because the program depends on you for input.      *" <<endl;
        cout << "  *  The only error check function it has, is for unacceptable opreators.   *" <<endl;
        cout << "  *  Acceptable operators are : (+ , - , / , * ,^,c). The character c sets  *" <<endl;
        cout << "  *  the value stored to ZERO. Enter Q to exit. ENJOY YOUR PROGRAM !!!!!!   *" <<endl;
        cout << "  ***************************************************************************" <<endl;
        cout << "                     " <<endl;
} 
int main()
{
    instructUser();
    double displayedVal;
    double newEntry;
    char command_character = 'C'; 
    displayedVal = 0.0;
    cout << "  Enter a number: " ;
    cin >> displayedVal;
    cout << "  Enter accepted Operator: " ;
    cin >> command_character;
    while (command_character != 'Q' || command_character != 'q')
    {
        switch(command_character)
        {
        case 'c':
        case 'C': displayedVal = 0.0;
                  break;
        case '+': cout << "  Enter a number: ";
                  cin >> newEntry;
                  displayedVal = displayedVal + newEntry;
                  break;
        case '-': cout << "  Enter a number: ";
                  cin >> newEntry;
                  displayedVal = displayedVal - newEntry;
                  break;
        case '*': cout << "  Enter a number: ";
                  cin >> newEntry;
                  displayedVal = displayedVal * newEntry;
                  break;
        case '/': cout << "  Enter a number: ";
                  cin >> newEntry;
                  do if (newEntry == 0)
                  {
                      cout << "  You cannot devide something by 0" << endl;
                      cout << "  Enter a number: ";
                      cin >> newEntry;
                  } while (newEntry == 0);
                  displayedVal = displayedVal / newEntry;
                  break;
        case '^': cout << "  Enter a number: ";
                  cin >> newEntry;
                  displayedVal = pow (displayedVal,newEntry);
                  break;
                  default : cout << "  Unacceptable Operator(" << command_character << ")" << endl;
        }
        cout << "  The result so far is: " <<displayedVal<< endl;
        cout << "  Enter Operator: ";
        cin >> command_character;

    }
    system ("pause");
    return 0;
}
 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.