Hello everyone,
I am in need of help in creating loop for the following scenario. I am new to java and have I am currently stuck on this one.
1 - one individual cupcake sold (for $2)
3 - a "package of 3" sold (for $5)
1 - one individual cupcake sold (for $2)
6 - a "package of 6" sold (for $8)
Build a program that will accept the input of each sale. Use a loop that will keep
accepting input until a sentinel value of 0 (zero) is entered. Ignore any input that is not 1 or 3 or 6; use
an if or select to accomplish this. While in the loop, you will accumulate the following three values:
* Total amount of dollar sales. For the input (what package size was sold), use an if or select to
determine the appropriate dollar sales to add. The prices are above; for example, if "3" is
entered, add $5 to the Total amount of dollar sales.
* Total number of cupcakes sold. Add the appropriate number; for example, if "6" is entered, add
6 to the Total number of cupcakes sold.
* Number of multi-cupcake packages sold. If the input package size sold is larger than 1, add one
to this counter. (This will accumulate "we sold 2 multi-cupcake packages", not count how many
cupcakes were in those packages.) Use an if or select to accomplish this.
Here is what I currently have
public static void main(String[] args) { //Initialize Variables int totalDollarSales = 0; int numberCupcakesSold = 0; int countMultiCupcakePackages = 0; int oneCupcake = 3; int threeCupcake = 5; int sixCupcake = 8; //Create a Scanner for Input Scanner input = new Scanner(System.in); //Loop cup cake counter //Read an initial input System.out.println("Enter package size sold: 1, 3, or 6: "); int data = input.nextInt(); //Keep reading data until the input is 0 int sum = 0; while (data !=0) { sum += data; //Read the next input System.out.println("Enter package size sold - 1, 3, or 6: "); data = input.nextInt(); }