Top

Simple Calculator


C++ Code
+ 0 likes
Please Register to submit score.
Bookmark and Share
Average Score  0.0 (of 0 scores)
Date Added  May 25, 2009
Last Updated  May 25, 2009
Tags  calculator 

Introduction

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

Grab the Code

#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;	
}

Comments

  (3)  RSS
Hawkee
Comments: 1,039
 
C++ Snippet:  Simple Calculator
Posted on May 25, 2009 8:28 pm
Did you write this? You can only post tested, working code of your own.
Purplebeard
Comments: 21
 
C++ Snippet:  Simple Calculator
Posted on May 25, 2009 9:11 pm
i have no idea what is wrong
BrAndo
Comments: 28
 
C++ Snippet:  Simple Calculator
Posted on Aug 21, 2009 7:27 pm
if you're wondering why you can't compile it, its because your not passing any variable in doDivideZero()

Commenting Options

Register or Login to Hawkee.com or use your Facebook or Twitter account by clicking the corresponding button below.

  
Bottom