- #1
JaysFan31
Hi. I'm completely new to Java, but I'm taking a course at a local university. I was wondering if someone could help me with this.
I need to create a program that counts change (pennies, nickels, dimes, quarters).
I've only been taking the class for about a week and am still very inexperienced when it comes to programming (and more importantly spotting errors). I modeled this program after a very similar one in my textbook. However, I cannot compile it using Dr. Java. Would someone mind helping me with some of the syntax errors I have made? Any help would be appreciated.
import java.util.Scanner;
public class CoinCounter {
public static void main(String[] args) {
// we define the variables that we need for our calculations
int quarters = 0, dimes = 0.0;
int nickels = 0; pennies = 0;
int total, num;
// we read in the values
Scanner scan = new Scanner(System.in);
System.out.println("How many quarters do you have:");
int quarters = scan.nextInt();
System.out.println("How many dimes do you have:");
dimes = scan.nextInt();
System.out.println("How many nickels do you have:");
nickels = scan.nextInt();
System.out.println("How many pennies do you have:");
pennies = scan.nextDouble();
// we perform the calculations
quarters + dimes + nickels + pennies = num;
total = 25 * quarters;
total = total + 10 * dimes;
total = nickels * 5 + total;
total = total + pennies;
// print the result
System.out.println("The number of coins you have is "
+ num);
System.out.println("And they are worth in cents: " total);
}
}
I need to create a program that counts change (pennies, nickels, dimes, quarters).
I've only been taking the class for about a week and am still very inexperienced when it comes to programming (and more importantly spotting errors). I modeled this program after a very similar one in my textbook. However, I cannot compile it using Dr. Java. Would someone mind helping me with some of the syntax errors I have made? Any help would be appreciated.
import java.util.Scanner;
public class CoinCounter {
public static void main(String[] args) {
// we define the variables that we need for our calculations
int quarters = 0, dimes = 0.0;
int nickels = 0; pennies = 0;
int total, num;
// we read in the values
Scanner scan = new Scanner(System.in);
System.out.println("How many quarters do you have:");
int quarters = scan.nextInt();
System.out.println("How many dimes do you have:");
dimes = scan.nextInt();
System.out.println("How many nickels do you have:");
nickels = scan.nextInt();
System.out.println("How many pennies do you have:");
pennies = scan.nextDouble();
// we perform the calculations
quarters + dimes + nickels + pennies = num;
total = 25 * quarters;
total = total + 10 * dimes;
total = nickels * 5 + total;
total = total + pennies;
// print the result
System.out.println("The number of coins you have is "
+ num);
System.out.println("And they are worth in cents: " total);
}
}