This is my assaigment:

Let's say that we can buy a candy from the vending machine for $1 each. Inside every candy is a coupon. We can redeem six coupons for one candy from the machine. This means that once you have started buying candy from the machine, you always have some coupons.

We would like to know how many candies can be eaten if we start with N dollars and we always redeem coupons if we have enough for an additional candy.

For example, with $6 we could consume 7 candy(s). After purchasing 6 candy(s), we have 6 coupons which we can redeem for an additional candy.

import java.util.Scanner;

public class Candy
{
public static void main(String[] args)
{
    int candy=0, left, dollar, coupons;





    System.out.println("How much money can you spend on candy?");
    Scanner keyboard = new Scanner(System.in);
    dollar = keyboard.nextInt();

    if(dollar < 6)
    {
        System.out.println(dollar%6 +"Coupons left");
    }

    while ( dollar >= 6){
    coupons = dollar / 6;
    candy++;
    left = dollar % 6;

    System.out.println("After redeeming coupons, you would have "+ left + " leftover");
    System.out.print("you purchase a total of " + candy + " candy.");
    break; 
    }
}


} 

When i input $6 the output is:
After redeeming coupons, you would have 0 leftover
you purchase a total of 1 candy(s).

but the output should be:
that I have 7 candy(s) because after 6 coupons I have 1 candy free.

I solved the problem
Thank you

commented: Thank you for telling us that you solved the problem yourself. (And "Good work!") +6
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.