0 Replies - 892 Views - Last Post: 07 November 2006 - 08:14 AM Rate Topic: -----

#1 sabin_gr18  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 03-November 06

Adding up in java to equal an amount help!

Posted 07 November 2006 - 08:14 AM

hey programming experrts i need your help on this one, im simulating a cashmachine in java code, it has three types of notes 5, 10, 20. as the user withdraws money i want each field to update for example, there are 2 fives, 2 tens and 2 twenties in the machine (which = 70) now if the user requests 35 pounds, the machine should take 1 away from each field. I know i have to use the smallest common denominator (5) which should keep adding up untill it reaches the amount requested, my problem is i dont know how to write this in java code, i want it to say keep adding 5 till it is equal to the amount requested, here is what i have done so far i think most of it is right its just that little bit of code (after the while loop statment and before the ==amount) i cannot do, plz can u help me out , thank you :)

int i = 5;
while(amount > 4){

==amount;
if(i = 20){
twenties = twenties - 1;
}
if( i = 10){
tens = tens - 1;

if( i = 5){
fives = fives - 1;

This post has been edited by sabin_gr18: 07 November 2006 - 08:15 AM


Is This A Good Question/Topic? 0
  • +

Page 1 of 1