Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: problem in simple program, new user

  1. #1
    Junior Member
    Join Date
    Dec 2011
    Thanked 0 Times in 0 Posts

    Default problem in simple program, new user

    I am trying to make a basic program that lets a user input a number, then it will tell them what coins make up this number. This is a project for school and im almsot finished but keep running into an error with my "originalAmount" variable. I have been looking up whats wrong for the past hour with no success so ive decided to ask for help. Here is my code thus far, any help would be great, even a hint!

    import java.util.Scanner;

    public class coins
    public static void main(String[] args)
    int amount, orginalAmount,
    quarters, dimes, nickels, pennies;

    System.out.println("Enter a whole number from 1 to 99.");
    System.out.println("This will tell you what coins make up your number");

    Scanner keyboard = new Scanner(System.in);
    amount = keyboard.nextInt();

    quarters = amount / 25;
    amount = amount % 25;
    dimes = amount / 10;
    amount = amount % 10;
    nickels = amount / 5;
    amount = amount % 5;
    pennies = amount;

    System.out.println(originalAmount +
    " cents in coins can be given as:");
    System.out.println(quarters + " quarters");
    System.out.println(dimes + " dimes");
    System.out.println(nickels + " nickels and");
    System.out.println(pennies + " pennies");

  2. #2
    Member snowguy13's Avatar
    Join Date
    Nov 2011
    In Hyrule enjoying a chat with Demise and Ganondorf
    My Mood
    Thanked 48 Times in 42 Posts

    Default Re: problem in simple program, new user

    Do you ever define original amount? I see the statement:

    int amount, originalAmount,...

    but nowhere do I see you actually assign a value to originalAmount. You could fix this with a simple statement by assigning amount's value to originalAmount, but make sure this is before you do anything with amount.

    Also note that you misspelled "originalAmount" in your declaration; you have it spelled "orginalAmount".

    Hopefully this helps!
    Use highlight tags to help others help you!

    [highlight=Java]Your prettily formatted code goes here[/highlight]

    Using these tags makes your code formatted, and helps everyone answer your questions more easily!

    Wanna hear something funny?

    Me too.

  3. The Following User Says Thank You to snowguy13 For This Useful Post:

    musterdplug12 (December 4th, 2011)

  4. #3
    Junior Member
    Join Date
    Dec 2011
    Thanked 0 Times in 0 Posts

    Default Re: problem in simple program, new user

    ever have one of those days where your brain seems to not function, cant believe i misspelled that, thanks man!! solved...

Similar Threads

  1. [SOLVED] Really simple program problem
    By Jacksontbh in forum What's Wrong With My Code?
    Replies: 3
    Last Post: June 29th, 2011, 10:15 PM
  2. urgent simple help for a very simple program
    By albukhari87 in forum Java Applets
    Replies: 4
    Last Post: June 5th, 2010, 03:43 PM
  3. How to make user press enter to continue in program?
    By BC2210 in forum File I/O & Other I/O Streams
    Replies: 3
    Last Post: October 3rd, 2009, 05:08 AM
  4. Replies: 1
    Last Post: July 28th, 2009, 02:15 AM
  5. Problem while implementing a basic user interface menu
    By Rastabot in forum File I/O & Other I/O Streams
    Replies: 3
    Last Post: April 3rd, 2009, 04:38 PM

Tags for this Thread