Reputation: 1
I was coding this "Change Making Program", where the code outputs the number of dollar bills, quarters, dimes, nickels, and pennies for an input of change that the cashier would give back. I casted the divisions to int, and I really can't see what I did wrong.
import java.util.Scanner;
class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Amount of Change to give: ");
double ch = input.nextInt();
int dollars = 0;
int quarters = 0;
int dimes = 0;
int nickles = 0;
int pennies = 0;
if(ch >= 1) {
dollars = (int)(ch / 1);
ch = ch % 1;
} if(ch >= 0.25) {
quarters = (int)(ch / 0.25);
ch = ch % 0.25;
} if(ch >= 0.1) {
dimes = (int)(ch / 0.1);
ch = ch % 0.1;
} if(ch >= 0.05) {
nickles = (int)(ch / 0.05);
ch = ch % 0.05;
} if(ch >= 0.01) {
pennies = (int)(ch / 0.01);
ch = ch % 0.01;
}
println("Number of Dollars: " + dollars);
println("Number of Quarters: " + quarters);
println("Number of Dimes: " + dimes);
println("Number of Nickles: " + nickles);
println("Number of Pennies: " + pennies);
}
}
I got those errors for each println()line that I have:
Main.java:36: error: cannot find symbol
println("Number of Pennies: " + pennies);
^
symbol: method println(String)
location: class Main
5 errors
compiler exit status 1
Upvotes: 0
Views: 102
Reputation: 785
you should write
System.out.println("Number of Dollars: " + dollars)
instead of println()
Upvotes: 2