Thanks for your reply. I've manage to display the money as I want now. One quick question:
since I'm using the values for calculations and I don't know the problem, can I use this to compare values with d:
- double d = (int)((d1 * 100)) / 100.0;
My code is almost complete. But heres the last part.
*This is for giving change(money). The vending machine should not dispense the product if the customer has not inserted the exact amount in which the machine will have to give change. And if the machine is to give change it should have the necessary coins that are needed for the change.
I've been able to make this work for a full refund where nothing is bought and you just need to keep track of the current session.
Here what I've tried to do with the one I'm stuck on.
-
-
If foundChange=true;
-
-
if( condition ...)
-
{ foundChange=true;
-
code....
-
}
-
-
else
-
{
-
Output (Not enough change)
-
foundChange=false;
-
}
-
I'm trying to run a method that at first has a boolean variable that is first false. Then becomes true. When the if conditions within the method are exhausted(all ifs conditions are false) I thought that it would naturally execute the else part. And in this else part, I write the code that makes the boolean from true to false (have "foundChange=false") This I found necessary because only once the conditions ( I have many ifs in this method) has been checked will the system be able to know if it has the necessary coins (hence it can determine if foundChange=false or foundChange=true.
Obviously in another part of the code there is
-
if(foundChange=true)
-
code...
-
-
if (foundChange=false)
-
code...
within the code it calls another method that executes more code.
Sorry for being ambigous, but I will be submitting this. Anyway whats happening is whichever is above is being executed. I don't understand why. So since here I have put "if (foundChange=true)" on top this gets executed. If I put "if(foundChange=false)" on top this gets executed. I don't get it. Its as if within the if condition it is getting assigned. I tried putting "==" instead still not working.
I've been able to do the entire question, this is the only one left.If you have a better idea please let me know (here's the problem*)
Regards,
John