I am working on a small program for school "vending machine". The basics of it are, you must pay for items with 1 dollar ( 100 ), and all items cost between 25 - 100 in increments of 5. The program must return the change in the following format:
X Quarters ( if not 0 )
X Dimes ( if not 0 )
X Nickels ( if not 0 )
If 0, then it skips the line, prints nothing and continues on.
I cant get the logic right:
int Change = (100 - ItemCost);
int Quarters = (Change / 25);
int Dimes = (insert logic help neowinians!);
int Nickels = (insert logic help neowinians!);
System.out.printf("Your change is %s cents.\n", Change);
if(Quarters != 0)
System.out.printf("%s Quarter(s)\n", Quarters);
else System.out.println();
if(Dimes != 0)
System.out.printf("%sDime(s)\n", Dimes);
else System.out.println();
if(Nickels != 0)
System.out.printf("%sNickel(s)\n", Nickels);
else System.out.println();
Question
Alladaskill17
I am working on a small program for school "vending machine". The basics of it are, you must pay for items with 1 dollar ( 100 ), and all items cost between 25 - 100 in increments of 5. The program must return the change in the following format:
X Quarters ( if not 0 )
X Dimes ( if not 0 )
X Nickels ( if not 0 )
If 0, then it skips the line, prints nothing and continues on.
I cant get the logic right:
int Change = (100 - ItemCost); int Quarters = (Change / 25); int Dimes = (insert logic help neowinians!); int Nickels = (insert logic help neowinians!); System.out.printf("Your change is %s cents.\n", Change); if(Quarters != 0) System.out.printf("%s Quarter(s)\n", Quarters); else System.out.println(); if(Dimes != 0) System.out.printf("%sDime(s)\n", Dimes); else System.out.println(); if(Nickels != 0) System.out.printf("%sNickel(s)\n", Nickels); else System.out.println();Link to comment
Share on other sites
8 answers to this question
Recommended Posts