Input to change program

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • PBJ
    New Member
    • Sep 2007
    • 4

    Input to change program

    I cant seem to get this right im tring to find the optimal solution and the user imput is 219 how do i get the user to imput a number and what is wrong with my coding am i atleast close HELP


    [CODE=java]public class Makechange
    {
    public static void main (String []args)
    {
    }
    {
    System.out.prin tln (" Please Enter number:" );



    int dollars = amount / 100;
    //number of dollars
    int dollarValue = dollars % 100;
    // value of quarters
    int amount;
    amount = dollarsValue;


    int quarters = amount / 25;
    //number of quarters
    int quartersValue = quarters % 25;
    //value of quarters
    amount -= quartersValue;


    int dimes = amount / 10;
    //number of dimes
    int dimesValue = dimes % 10;
    // The value of the dimes
    amount -= dimesValue;


    int nickels = amount / 5;
    //number of nickels
    int nickelsValue = nickels % 5;
    //value of nickels
    amount -= nickelsValue;

    int pennies = amount/ 1;
    //number of pennies
    int penniesValue = pennies % 1;
    //value of pennies
    amount -= penniesValue;




    System.out.prin tln ("Dollars: " + dollars);
    System.out.prin tln ("Quarters: " + quarters);
    System.out.prin tln ("Dimes: " + dimes);
    System.out.prin tln ("Nickels: " + nickels);
    System.out.prin tln ("Pennies: " + pennies);
    }
    }[/CODE]
    Last edited by Ganon11; Sep 8 '07, 01:54 PM. Reason: Please use the [CODE] tags provided.
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Your logic w.r.t. dollars, quarters, dimes etc. seems correct; you forgot to read
    the 'amount' variable which is crucial here. Have a look at the Scanner class.

    kind regards,

    Jos

    Comment

    • PBJ
      New Member
      • Sep 2007
      • 4

      #3
      Originally posted by JosAH
      Your logic w.r.t. dollars, quarters, dimes etc. seems correct; you forgot to read
      the 'amount' variable which is crucial here. Have a look at the Scanner class.

      kind regards,

      Jos
      what exactly do you mean my brain is kinda fried been working on this go 8 hours

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        Originally posted by PBJ
        what exactly do you mean my brain is kinda fried been working on this go 8 hours
        Exactly as I wrote: you prompt the user to enter a number but there is no code
        whatsoever that actually reads a number; I suggested to use a Scanner class
        for the reading.

        kind regards,

        Jos

        Comment

        • r035198x
          MVP
          • Sep 2006
          • 13225

          #5
          I've changed your thread title to something more specific to your problem. Please remember that next time.
          Also use code tags everytime when posting code in the forums.

          Comment

          • kreagan
            New Member
            • Aug 2007
            • 153

            #6
            Originally posted by PBJ
            what exactly do you mean my brain is kinda fried been working on this go 8 hours
            It's okay. Whenever someone says: look at [insert name here] class, they mean refer to Java's API. Remember, Java.sun.com is your best Java friend.

            Java API

            Here you will find this link:

            Scanner Class

            Scanner class allows you to take input from the user. I would suggest reading the documentation presented in this document because I can't explain it as well as Sun can.

            Furthermore, I think there is something funky going on with your brakets. Are you sure it does anything? or even compiles?

            Comment

            Working...