Results 1 to 6 of 6
  1. #1
    Jtward86 is offline Member
    Join Date
    Sep 2012
    Posts
    2
    Rep Power
    0

    Default Trying to write a program, not sure what I am doing wrong.

    Hey everyone,

    I am in a basic java programming class and it is just whipping my butt! This is extremely hard for me seeing as how I prefer the hardware side of things. Any ways, here is the problem:

    Suppose we can buy a chocolate bar from the vending machine for $1 each. inside every chocolate bar is a coupon. We can redeem six coupons for one chocolate bar from the machine. This means that once you have started buying chocolate bars from the machine, you always have some coupons. We would like to know how many chocolate bars can be eaten if we start with N dollars and always redeem coupons if we have enough for an additional chocolate bar.

    And here is my code:
    Java Code:
    import java.util.Scanner;
    
    public class ChocolateCoupons
    {
    public static void main(String[] args)
    {
    int bars  leftover  dollars  coupons;
    
    d = dollars;
    l = leftover;
    b = bars;
    c = coupons;
    
    b = d;
    c = d / 6;
    
    
    System.out.println("How much money can you spend on chocolate bars?");
    Scanner keyboard = new Scanner(System.in);
    d = keyboard.nextInt();
    
    while (coupons >= 6);
    c = d / 6;
    b+=;
    l = d % 6;
    
    System.out.print("After redeeming coupons, you would have ");
    System.out.print( l );
    System.out.print(" leftover ");
    System.out.print("coupons and can purchase a total of "); 
    System.out.print( b );
    System.out.println(" chocolate bars.");
    }
    }
    And this is what my programming lab says as hints:
    ⇒*****You should be using: +
    *****⇒*****Are you sure you want to use: b
    *****⇒*****Are you sure you want to use: d
    * • Are you sure you want to use: c
    * • Are you sure you want to use: leftover
    * • Are you sure you want to use: print

    Hoping you guys could give out a few pointers as why this program doesn't work. Logically it looks right to me but I am guessing my syntax is all off

    Thanks
    Last edited by Jtward86; 09-25-2012 at 04:50 AM.

  2. #2
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,934
    Rep Power
    19

    Default Re: Trying to write a program, not sure what I am doing wrong.

    Not sure how you're compiling this, because that is not a compiler error output.
    Also please use [code] tags [/code] when posting code.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    Jtward86 is offline Member
    Join Date
    Sep 2012
    Posts
    2
    Rep Power
    0

    Default Re: Trying to write a program, not sure what I am doing wrong.

    Dont really have a compile report because the educational tool doesnt really use one. Let me ask this. Does my program do what the question asks? If so then I know I just have some syntax problems which I should be able to fix.

    If the program doesnt do what it should then I have a problem cause I am not sure how to fix it

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: Trying to write a program, not sure what I am doing wrong.

    Please go through the Forum Rules -- particularly the third paragraph.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: Trying to write a program, not sure what I am doing wrong.

    Quote Originally Posted by Jtward86 View Post
    Does my program do what the question asks? If so then I know I just have some syntax problems which I should be able to fix.
    If your code has syntax errors, it doesn't compile, hence the question of doing anything at all -- what the question asks or otherwise -- does not arise.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  6. #6
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,934
    Rep Power
    19

    Default Re: Trying to write a program, not sure what I am doing wrong.

    We could point out where the syntax errors are, but if this is going through some other software then there is no guarantee that it is supposed to by syntactically correct Java.

    For starters you have several variables there that don't seem to be declared anywhere.
    There are commas missing as well.
    The later hints seem to be suggesting using '+' to concatenate your output together rather than separate print() statements, and using a single println() call, though I can't guarantee that is a fair interpretation.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. What is wrong with my program?
    By icykum in forum New To Java
    Replies: 3
    Last Post: 09-23-2012, 10:34 PM
  2. Replies: 7
    Last Post: 11-30-2011, 06:58 PM
  3. What is wrong with this program!?
    By flecdorbee in forum New To Java
    Replies: 5
    Last Post: 02-26-2011, 01:11 AM
  4. what the wrong in my program ><
    By MSs.Java in forum New To Java
    Replies: 4
    Last Post: 05-03-2010, 01:28 PM
  5. What's wrong in my program...?
    By Annatar in forum Java Software
    Replies: 3
    Last Post: 10-31-2008, 06:03 AM

Posting Permissions

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