![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Apr 2005
Posts: 2
Rep Power: 0
![]() |
hi guys, im a new member here. i hope i can find a solution for my problem.
i have been assigned a project in C language that requires us to build a non-scientific calculator. The user should give the instructions as a sequence ending with sentinel “=” and the program should calculate the result without considering the precedence of the operators. the sequence can be any length. The operators that must be used are: + (addition), - (subtraction), * (multiplication), / (division), ^ (power) my problem is that i could not make the program calculate the results.... i enter the sequence ending with the sentinel '=' but the calculations are not done... i will be so glad if anyone can helpppp thanks |
|
|
|
|
|
#2 |
|
Programmer
Join Date: Feb 2005
Posts: 89
Rep Power: 4
![]() |
you get a lot more help if you post some code that you have worked on.
my c is rusty, but in c++, this is really easy. cin>> an int, then a char, then another int. use the character (+-*/^) as an argument to a doMath kinda function, and ints 1 and 2 as operands. in c++, a simple version (without bad input catching) can be written in about 10-15 lines of code. should be about the same in c. i'm just trying to remember how the get and getch work. i'm really out of practice. ![]() |
|
|
|
|
|
#3 |
|
Programming Guru
![]() ![]() ![]() |
lets see what you have done so far...
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
|
|
#4 | |
|
Programmer
|
Show your code, and then, if you haven't already done so, learn arrays and vectors pretty well.(Vectors may not be necesarry).
__________________
Quote:
|
|
|
|
|
|
|
#5 |
|
The Supreme Ruler
![]() Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6
![]() |
I was thinking just get it as one long String. Use the +-/*^ characters to split the string into 4 ways, first integer, operator, 2nd integer an equal sign, and then use an atoi() function to get the ints you want, then just do the proper calculations. It sounds like you can basically disregard the equal sign and almost consider it always there. Of course, like others have said, I don't know exactly how far you've gotten since you haven't posted any of your code. Also, I could be making this harder than it is.
__________________
"Every gun that is made, every warship launched, every rocket signifies, in the final sense, a theft from those who hunger and are not fed, from those who are cold and are not clothed. The world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children." - Dwight D. Eisenhower |
|
|
|
|
|
#6 |
|
Expert Programmer
Join Date: Sep 2004
Location: Ontario, Canada
Posts: 555
Rep Power: 5
![]() |
Welcome to the forums dude
![]() Simple program...Post the code you have so far and we'll help you out ![]()
__________________
Johnny was a chemist's son but Johnny is no more, for what Johnny thought was H2O was H2SO4 |
|
|
|
|
|
#7 | |
|
Newbie
Join Date: Feb 2005
Posts: 22
Rep Power: 0
![]() |
Quote:
|
|
|
|
|
|
|
#8 |
|
Expert Programmer
Join Date: Dec 2004
Posts: 794
Rep Power: 4
![]() |
They are in C++, not in C. (You could program them yourself in C without too much trouble)
|
|
|
|
|
|
#9 | |
|
Newbie
Join Date: Feb 2005
Posts: 22
Rep Power: 0
![]() |
Quote:
|
|
|
|
|
|
|
#10 | |
|
Professional Programmer
Join Date: Apr 2005
Location: London, England
Posts: 459
Rep Power: 4
![]() |
Quote:
|
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|