Jump to content

Calculating Change Denominations w/ classes


Inked

Recommended Posts

Hi. So I'm trying to learn classes and how to use them with PHP and I'm stuck. I'm trying to make a script that takes input from a user of 2 amounts and stores them into variables. I would then like to use these variables in a couple of functions to make some calculations and finally echo my findings. I'm close but I've still got issues and it seems like I'm now running in circles.

 

I've been reading documentation on classes and googling, but I'm quite stuck. I'm hoping for perhaps some explanations. I could do what I need to do in just another php processing script. But I'm really trying to learn classes and how they can be used with other pages and how general they can be. Here's what I got so far:

 

CalculateChange.php

 

http://pastebin.com/ctdkYjXc#

 

class_Change.php

 

http://pastebin.com/gdfYGXwV#

Link to comment
Share on other sites

Well, at a glance you're still strugling with the scope of variables within methods.  Your validatePayed and calculateChange methods are refferencing method specific variables $changeDue, $change, $oneHundred, $fifty etc.  and from your parameter devleration it looks like you're actually meening to refference the class parameters of the same name which would require the same $this-> prefix that you use to get the values of the paramter varialbes on the right of the assignments.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.