0

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.

1
Contributor
1
Reply
22
Views
3 Years
Discussion Span
Last Post by iTechnnn
1

I solved the problem
Thank you

Votes + Comments
Thank you for telling us that you solved the problem yourself. (And "Good work!")
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.