Results 1 to 4 of 4
  1. #1
    jjth39347 is offline Member
    Join Date
    Feb 2011
    Posts
    71
    Rep Power
    0

    Default compiles but I get errors, need help

    when ever I run it I always get an error when it displays change or how many years to wait, any one wanna help me out here?

    Java Code:
    import java.util.Scanner;
    public class Lab6_1
    {
    
    
    public static void main(String[] args)
    
    {
    
    int customerAge;
    int reqAge;
    int waitYears;
    double cashAmount;
    double cashReq;
    double cashNeeded;
    
    
    
    System.out.println("Please type customer age:");
    Scanner keyboard = new Scanner(System.in);
    customerAge = keyboard.nextInt();
    System.out.println("Type customer cash amount:");
    cashAmount = keyboard.nextDouble();
    
    
    reqAge = 21;
    cashReq = 5.00;
    waitYears = reqAge - customerAge;
    cashNeeded = cashReq - cashAmount;
    
    
    
    
    if (customerAge >= 21)
    {
    if (cashAmount >= 5.00)
    
    System.out.println("Congratulations, you can have some beer." );
    
    else
    
    System.out.printf("Sorry, you need $%.2 more.%n" , cashNeeded);
    }
    else
    {
    System.out.println("No beer for you!");
    System.out.printf("Come back in %.1f years. %n" , waitYears );
    }
    
    
    System.out.println("Thank you for your patronage.");
    
    
    
    
    }
    
    }

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

    Default

    Quote Originally Posted by jjth39347 View Post
    when ever I run it I always get an error when it displays change or how many years to wait, any one wanna help me out here?
    Sure, but don't keep the error messages secret. Please share them with us as well as which lines cause the errors.

  3. #3
    jjth39347 is offline Member
    Join Date
    Feb 2011
    Posts
    71
    Rep Power
    0

    Default

    well it works for me now, turns out I forgot the "f" after %.2 in the printf statement lol, but the friend I'm trying to help with this is still getting problems. I'll ask them for the errors they are getting

  4. #4
    jjth39347 is offline Member
    Join Date
    Feb 2011
    Posts
    71
    Rep Power
    0

    Default

    sorry for the trouble, turns out it just wasn't saved right.

Similar Threads

  1. Replies: 6
    Last Post: 02-08-2011, 02:29 AM
  2. Replies: 4
    Last Post: 01-04-2011, 12:36 AM
  3. compiles but dosent work...
    By darkflame5019 in forum New To Java
    Replies: 8
    Last Post: 01-01-2011, 07:22 PM
  4. compiles; no display
    By skuzzie in forum New To Java
    Replies: 5
    Last Post: 12-18-2010, 07:57 PM
  5. Errors driving me crazy! although compiles fine
    By irishsea2828 in forum New To Java
    Replies: 1
    Last Post: 04-08-2008, 03:23 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
  •