Results 1 to 3 of 3
  1. #1
    coding is offline Member
    Join Date
    Jan 2011
    Posts
    40
    Rep Power
    0

    Default How do you do in an input and then get an output?

    How do you make it so it ask you how much money you have used, and the amount of money you have left and it subtracts it and tells you how much you have left in bills?

    Lets say you used $20.26 , and you originally had 40 dollars you put 20.26 as the amount you spent and then you put 40 as the original amount and it outputs it as the answer as 19.74 dollars and then it breaks it down further and tells you you have 19 dollars 2 quarters 2 dimes and 4 pennies?

    I'm have a hard time figuring out how to code that

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: How do you do in an input and then get an output?

    Please help us help you: What have you tried? How is your attempt not working? Where specifically are you stuck?

  3. #3
    coding is offline Member
    Join Date
    Jan 2011
    Posts
    40
    Rep Power
    0

    Default Re: How do you do in an input and then get an output?

    I've done this
    public class s {
    public static void main(String[] args)
    {
    int a ;
    int b ;
    int sub;
    @SuppressWarnings("resource")
    Scanner input = new Scanner(System.in);
    System.out.println("Please enter purchase amount:"); //Ask user for first input.
    a=input.nextInt(); // store the input a.
    System.out.println("Please enter amount tendered :"); // Ask user for second input.
    b=input.nextInt(); // store the input in b.

    sub = a - b; //subtract the 2 two numbers

    System.out.println("Your change is : " + sub); // display the result of the two numbers

    }
    }
    And when I enter normal numbers its fine, but when i enter decimals like 10.5 i get an error and idk how it can break up the answers in dollars, quartiers, dimes and pennies.

Similar Threads

  1. Input/Output without java.io
    By Arka in forum New To Java
    Replies: 2
    Last Post: 07-18-2012, 10:32 AM
  2. Input Output stream
    By kazuhiko in forum Networking
    Replies: 13
    Last Post: 03-15-2012, 05:43 PM
  3. Input/ output file
    By 3MAD in forum New To Java
    Replies: 1
    Last Post: 04-15-2011, 01:59 PM
  4. File input output
    By edcaru in forum New To Java
    Replies: 5
    Last Post: 12-19-2010, 06:52 PM
  5. help with data output, input
    By collin389 in forum New To Java
    Replies: 3
    Last Post: 11-11-2009, 06:34 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •