# Simple Calculator

### By miniCruzer on May 25, 2009

Calculator. I can't figure out what's wrong though. Anyone wanna help?

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

void instructUser();
double doDivideZero(double &);

int main()
{
instructUser();

double displayedVal;
double newEntry;
char command_character ;

displayedVal = 0.0;

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 Number:";
cin >> newEntry;
displayedVal = displayedVal + newEntry;
break;
case '-': cout << "  Enter Number:";
cin >> newEntry;
displayedVal = displayedVal - newEntry;
break;
case '*': cout << "  Enter Number:";
cin >> newEntry;
displayedVal = displayedVal * newEntry;
break;
case '/': cout << "  Enter Number:";
cin >> newEntry;
displayedVal = displayedVal / newEntry;
if (newEntry == 0)
{
doDivideZero(double &);
}

break;
case '^': cout << "  Enter 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;
}

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;

}

double doDivideZero(double &)
{
double newEntry;
double displayedVal;
newEntry =0;
displayedVal = 0.0;

if (newEntry !=0)
{
displayedVal = displayedVal / newEntry;
} else cout << "Wrong Operation, Cannot Divide by Zero" << endl;

return 0;
}
``````

AlexRapso   -  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;
}
``````
AlexRapso   -  Apr 23, 2010

error C2144: syntax error : 'double' should be preceded by ')'

``````if (newEntry == 0)
{
doDivideZero(double &);
}
``````
BrAndo   -  Aug 21, 2009

if you're wondering why you can't compile it, its because your not passing any variable in doDivideZero()

Purplebeard   -  May 25, 2009

i have no idea what is wrong

Hawkee   -  May 25, 2009

Did you write this? You can only post tested, working code of your own.

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.