PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Im taking a computer sciences course here at school. The teacher gave us a crash course of PHP in 3 classes. Needless to say, this was hardly enough and Im stil left flying blind. He gave us a very, very hard assignment. We must code a calculator. Now, I know plenty are available on the net, However, not this kind. Every other calculator I find is usually a 2 box calculator you type the numbers in and select the operator, then push submt. This calculator must be like an actual calculator, with the numbers you push adding onto a big string of them and then you push the operator and then you push the second numbers and then equals. It must look like a real calculator. I have uploaded my code to a txt document on geocities, Which is linked http://www.geocities.com/raptor_aximili/phpcalc.txt
Just view source that, and that will be my entire PHP code.
Just from the initial description of your project this sounds like an AJAX app. Pressing buttons and operators and having them display is really not going to happen without page submits, which would almost necessitate using a client side technology.
It is an option, but honestly, a simple calculator can be handled with JavaScript without touching PHP. Besides, if the desired effect is to push a series of numeric buttons that populate the calulcator 'bar' as they are being entered, that will not happen with PHP unless everytime you hit a button the page sends a new request to the server. That would be the slowest calculator around .
AJAX all the way for something like this, in my opinion.
Last edited by RobertGonzalez on Mon Jun 05, 2006 11:56 am, edited 1 time in total.
I'd use javascript to create the numbers and then make the operators form submits to act on the number.
Probably need session variables too to build the calculation!
Sounds like a challenge - by school do you mean university level (our American cousins have butchered the English language ) or under 18? under 16?!!!
Last edited by andym01480 on Mon Jun 05, 2006 11:56 am, edited 1 time in total.
I don't want to be rude but your instructor sounds like an idiot and you should inform him of this.
Is it possible you were placed in a more advanced class than you had intended or something because I see this task as being impossible for someone with only a basic knowledge of HTML and PHP. As you said before.
I would tell him that his request is unreasonable and refuse, talk to an administrator.
Then again, I was expelled several times from different schools and never graduated high school, so you may not want to listen to me lol
You need to head to borders and read all day and all night. Just change chairs every half an hour or so and they will never notice, the place is like a library.
Raptor Cardel wrote:Well, how about for curiosity sake we actually code it to submit with every button? We do have a dedicated server for this project...
To do this you would have to have your code setup in such a way as to know the difference between a number and an operator and equals "=". I would probably keep track of what was submitted numerically until an operator was selected, then store what was in number into a session var along with the operator, then repeat the process for the second number, then when equals is hit, throw the whole equation together and valuate it. This is insanely slow, but doable.
Daedalus- wrote:You need to head to borders and read all day and all night. Just change chairs every half an hour or so and they will never notice, the place is like a library.
I'm of the opinion that you should use AJAX. Not only does it make sense given your criteria. It will also impress (Maybe...)