Hi everyone. I am a beginner of beginners in Java. I'm not a CS or programming major but I am now taking a Java course because it is required. I look forward to hearing your insight.
I'm working on a program that is designed to make change from an entered value, only using Ten, Five, and One dollar bills and Quarters, Dimes and Nickels. The amount must round up to the nearest nickel. So for example if I entered $35.77, the output should be something like;
Ten dollar bills: 3
Five dollar bills: 1
One dollar bills: 0
Quarters: 3
Dimes: 0
Nickels: 1 //because it is rounding up.
I'm very confused on what methods I should be using to write this program. This is what I have so far, can someone tell me what is wrong? Thank you in advance, much appreciated.
Basically what I've done so far is convert the amount entered into cents. Than dividing it by the appropriate amount to convert it into Tens, Fives, Ones etc. Than subtracting that from the amount entered. I declared a variable "change" and "difference" but I have not used them below yet. Thanks again!
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
import java.util.Scanner;
public class makingChange
{
public static void main(String[] args)
{
Scanner scan=new Scanner(System.in);
double amt,totalCents,change, difference;
double ten,five,one,quarter,dime,nickel;
ten=0;
five=0;
one=0;
quarter=0.0;
dime=0.0;
nickel=0.0;
System.out.println("Please enter the amount to be changed");
amt=scan.nextDouble();
totalCents= amt*100;
//difference=
ten=amt-(totalCents/1000);
five=amt-(totalCents/500);
one=amt-(totalCents/100);
quarter=amt-(totalCents/25);
dime=amt-(totalCents/10);
nickel=amt-(totalCents/5);
System.out.println("Ten dollar bills: " + ten);
System.out.println("Five dollar bills: " + five);
System.out.println("One dollar bills: " + one);
System.out.println("Quarters: " + quarter);
System.out.println("Dimes: " + dime);
System.out.println("Nickels: " + nickel);
}
}