java - I am writing a program for a class that involves inputting and keeping track of totals and sub totals for each individual person in a restaurant -
package restaurantmenu; import java.util.scanner; public class restaurantmenu { public static void main(string[] args) { scanner input = new scanner(system.in); string[] itemname = { " ", "soup", "wings", "burger", "chicken sandwich", "fries", "pie", "ice cream", "soft drink", "coffee" }; double[] itemprice = { 0, 2.50, .15, 4.95, 5.95, 1.99, 2.95, 2.99, 1.50, 1.00 }; double grandtotal = 0; double total = 0; system.out.println("how many people in party? "); int partynumber = input.nextint(); (int = 0; < partynumber; i++) { system.out.println("discount type:"); system.out.println("--------------"); system.out.println("1: child"); system.out.println("2. teen"); system.out.println("3: senior"); system.out.println("4. none of above"); int discount = input.nextint(); (int k = 0; k < itemname.length; k++) { system.out.println(itemname[k] + " "); } (int j = 1; j <= 3; j++) { system.out.println("please select menu item: "); int itemnum = input.nextint(); if (itemnum == 2) { system.out.println("how many want? "); int amount = input.nextint(); itemprice[2] = itemprice[2] * amount; } total = total + itemprice[itemnum]; } system.out.println(total); if (discount == 1) total = total * 0; else if (discount == 2 || discount == 3) total = total * .75; else total = total + (total * .05); grandtotal = total; } system.out.println(grandtotal); } }
so, i'm thinking total not resetting upon jumping out of second loop, don't know if need to. i'm wondering why can't total track properly, output grandtotal
, , discount multiple people. if needs input data provided me teacher let me know.
at end of englobing loop, reset total, , grandtotal must add total.
grandtotal += total; total = 0;
Comments
Post a Comment