•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 391,588 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,643 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser:
Views: 27751 | Replies: 4
![]() |
•
•
Join Date: Nov 2004
Posts: 6
Reputation:
Rep Power: 0
Solved Threads: 0
I am doing something wrong, I have tried for two days and I still cannot figure it out. Can someone help me? Thank you.
:cry: :cry: :cry:
#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;
} Last edited by alc6379 : Nov 1st, 2004 at 11:06 pm. Reason: added [code] tags
•
•
Join Date: Sep 2004
Location: Overflow State
Posts: 183
Reputation:
Rep Power: 4
Solved Threads: 4
Greetings kisseric,
Try changing the line: To: Once I did this, your program ran just fine. I compiled it in Dev-C++.
- Stack Overflow
Try changing the line:
if (newEntry == 0)
{
doDivideZero(double &);
}if (newEntry == 0)
{
doDivideZero(displayedVal);
}- Stack Overflow
Following the rules will ensure you get a prompt answer to your question. If posting code, please include BB [code][/code] tags. Your question may have been asked before, try the search facility.
IRC
Channel: irc.daniweb.com
Room: #c, #shell
IRC
Channel: irc.daniweb.com
Room: #c, #shell
•
•
Join Date: Feb 2002
Location: Lawn Guylen, NY
Posts: 10,879
Reputation:
Rep Power: 32
Solved Threads: 106
Also, check this line:
You need to name your variable, such as (double& x)
double doDivideZero(double &)
You need to name your variable, such as (double& x)
Dani the Computer Science Gal
Do you run a computer-related website? Feature it in our niche link directory!
Do you run a computer-related website? Feature it in our niche link directory!
•
•
Join Date: Oct 2004
Location: Mojave Desert
Posts: 2,394
Reputation:
Rep Power: 9
Solved Threads: 172
Forget about your doDivideZero function and replace some of your code with
[php] case '/': cout << " Enter Number:";
cin >> newEntry;
if (newEntry == 0)
{
cout << "Wrong Operation, Cannot Divide by Zero" << endl;
newEntry = 1;
}
displayedVal = displayedVal / newEntry;
break;
[/php]
This keeps the program going ...
[php] case '/': cout << " Enter Number:";
cin >> newEntry;
if (newEntry == 0)
{
cout << "Wrong Operation, Cannot Divide by Zero" << endl;
newEntry = 1;
}
displayedVal = displayedVal / newEntry;
break;
[/php]
This keeps the program going ...
May 'the Google' be with you!
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
- starting a calculator program in C (C)
- Java Swing Calculator program not running. It has 0 errors (Java)
- having problems to complete implement a simple calculator program in c (C)
- Wierd error messages with calculator program (C++)
- need hekp with C++ Calculator program (C++)
- need help with calculator program in C (C)
Other Threads in the C++ Forum
- Previous Thread: how to add data from an array to a stack
- Next Thread: need links wher i can find c++ codes lots of them!!!



Linear Mode