Ask Experts Questions for FREE Help !
Ask
    sdken8's Avatar
    sdken8 Posts: 1, Reputation: 1
    New Member
     
    #1

    Oct 1, 2012, 09:33 AM
    Java padding for currency
    Hello,

    I'm making a simple currency java program, and for the most part, it works well. What it is, is the user inputs the number of coin types, and the program will output the total in $x.xx format. My problem is that if the pennies total less than 10, it will display incorrectly. For example try typing 4 quarters, 0 dimes, 0 nickels and 1 penny. Here is the code:

    import java.util.Scanner;

    public class ValueOfCoins {

    public ValueOfCoins() {

    }

    public static void main(String[] args)

    {

    int quarters;
    int dimes;
    int nickels;
    int pennies;
    int total;

    Scanner scanner = new Scanner (System.in);
    System.out.print("Enter the number of quarters: ");
    quarters = scanner.nextInt();
    System.out.print("Enter the number of dimes: ");
    dimes = scanner.nextInt();
    System.out.print("Enter the number of nickels: ");
    nickels = scanner.nextInt();
    System.out.print("Enter the number of pennies: ");
    pennies = scanner.nextInt();

    int totalInCents = quarters * 25 + dimes * 10 + nickels * 5 + pennies;
    total = totalInCents / 100;
    totalInCents = totalInCents % 100;

    System.out.println("The value of these coins is $" + total + "." + totalInCents);

    }

    }

    Thanks in advance!

    -Ksd

Check out some similar questions!

How do you keep the padding in your bras from getting all messed up in the washer? [ 7 Answers ]

How do you keep the padding in your bras from getting messed up in the washer and dryer, and how do you fix it after there all messed up?? >Moved from Humor & Comedy<

Padding numbers in excel [ 2 Answers ]

I have about 500,000 cells on a spreadsheet that all follow a letter and number pattern. There are two patterns that look like this: y124f07 and h67g02. So the first is: Letter, number, number, number, letter, number, number The second is: Letter, number, number, letter, number, number

You.S. Currency [ 4 Answers ]

I'd like to know 1928 silver certificate star note graded CGA 63 unc. Is worth. Please confirm Thanks Paul

Laminate flooring double padding? [ 3 Answers ]

Hello, I am about to install laminate flooring on a 2nd floor condo. Can I install double padding Underneath to deaden/eliminate noise? Will it make a difference in noise for downstairs neighbors? Or is double padding not adviseable. Will there be any Con issues using two pads? I do plan on...


View more questions Search
 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.