You have an old version of Visual C++ then. 2K3 Toolkit doesn't have that warning message - when no return value is given, the compiler implicitly returns 0.Originally Posted by InvariantLoop
You have an old version of Visual C++ then. 2K3 Toolkit doesn't have that warning message - when no return value is given, the compiler implicitly returns 0.Originally Posted by InvariantLoop
Im using Microsoft Visual C++ 6.0 standard edition.
When no one helps you out. Call google();
Also, to the OP, you're looking for this, I do believe.
Yeah, that's pre-standard. Upgrade.Originally Posted by InvariantLoop
It turns out that you don't need to own "The C++ programming language" to get the code for the "Desk Calculator". You might be interested in looking as a learning experience, but obviously I don't recommend turning this in as your project (I'm sure what you've got is fine for the purposes of your class).
Here is the link:
http://www.research.att.com/~bs/dc.c
The crows maintain that a single crow could destroy the heavens. Doubtless this is so. But it proves nothing against the heavens, for the heavens signify simply: the impossibility of crows.
Here is how I would do this remeber there is no error checking so you enter a wrong thing to bad
Code:#include <iostream> int main() { int num1; int num2; char sign; char exitEntry; bool exit = false; std::cout<<"Welcome to a basic calculator"<<std::endl; while(!exit) { std::cout<<"Enter what calculation you want"<<std::endl; std::cin>>num1>>sign>>num2; switch(sign) { case '+': std::cout<<"It equals :"<<num1 + num2<<std::endl; break; case '-': std::cout<<"It equals :"<<num1 - num2<<std::endl; break; case '/': std::cout<<"It equals :"<<num1 / num2<<std::endl; break; case '*': std::cout<<"It equals :"<<num1 * num2<<std::endl; case 'e': exit = true; break; default: std::cout<<"Invalid operator"<<std::endl; } std::cout<<"Another y or n? "; std::cin>>exitEntry; if(exitEntry == 'n') { exit = true; } } std::cin.get(); return 0; }
Woop?
Did you ever consider that the poster may be doing an assignment for class?I'm very proub of myself first time I wrote something like this : its all in the mind :P
In addition, if you have a string of else-if statements, it's supposed to be more efficient to use a 'switch statement', which does the exact same thing as a bunch of else-if statements, so you should familiarize yourself with a switch statement.
Thanks for the assistance, I was able to get it based on the information provided. I appreciate it.
Now, for the next part of this problem...
It's still the same program, what we're ultimately looking for here is to have the console ask.
**
cout << "Continue? ";
cin >> answer
**
answer will be a char value that only accepts y Y n or N as a valid value. If a y or Y is typed in it will then ask the equasion, and it will obviously exit if a n or N is entered.
**
cout << "Enter equasion: ";
cin >> num1 >> opcode >> num2
**
This all suppose to be done somehow with functions, I've got some ideas but I'm not sure how to do it.
Class? Yes. For a grade? No. No grades in this class.Originally Posted by 7stud
I guess you didnt read the code prog-bman posted.
When no one helps you out. Call google();
I did but you have to understand that he's giving me coding options for code we haven't gotten to in the class yet. It works just peachy but the instructor will go "Where the hell did you learn this at?"Originally Posted by InvariantLoop
This sort of works, it lets me do what I want the only problem I have is that it doesn't exit on the "Continue" when I type n or any other letter.Code:#include <iostream> using namespace std; int doEquasion(); int main() { char cont; cout << "Continue? "; cin >> cont; while(cont == 'y' || cont == 'Y') doEquasion(); } doEquasion() { int num1, num2, answer; char opcode; cout << "Enter Equasion: "; cin >> num1 >> opcode >> num2; if (opcode == '+') { answer = num1 + num2; cout << answer << endl; } else if (opcode == '-') { answer = num1 - num2; cout << answer << endl; } else if (opcode == '*') { answer = num1 * num2; cout << answer << endl; } else if (opcode == '/') { answer = num1 / num2; cout << answer<< endl; } else cout << "Invalid Operator\n"; char cont; cout << "Continue? "; cin >> cont; return answer; }
Last edited by jcmhex; 03-10-2005 at 09:21 AM.
>>it doesn't exit on the "Continue" when I type n or any other letter.
The problem is simply that you're asking "Continue?" in doEquasion() (it's spelled 'equation' ), while the loop that you're trying to break is in main(). Although the 2 variables are named the same ('cont') in both functions, they are NOT the same, so the 'cont' in main() will never change. The simplest solution I can think of is just to put the prompt for continue in the while loop instead of inside doEquasion(). I have to go right now, but if what I just said doesn't make much sense to you, then just ask
Just Google It. √
(\ /)
( . .)
c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.
equation