- int num;
- final int MAX = 5;
- double price1, price2, price3, price4, price5;
- String descript;
- String another = "y";
-
- while (another.equalsIgnoreCase("y"))
- {
-
- System.out.println("Starting new customer...");
- System.out.print("How many items are being purchased: ");
- num = sc.nextInt();
-
- while (num > MAX || num <=0)
- {
- System.out.println("Invalid input. Please enter again.");
- System.out.print("How many items are being purchased: ");
- num = sc.nextInt();
- }
-
- if (num > 0 && num <= MAX)
- {
- int count = 1;
- do
- {
-
- System.out.print("Enter description of product #" + count + ": ");
- descript = sc.next();
-
- System.out.print("Enter price of "+ descript +": ");
- price1 = sc.nextDouble();
- count++;
- }
- while (count <= num);
-
- double total = price1;
-
- System.out.println("\n-------------------------------");
- System.out.println(" The Greengrocery");
- System.out.println(" Transaction: " + num + "");
- System.out.println(" Total Amount Due: $" + total + "");
- System.out.println("-------------------------------");
- }
複製代碼 要計個total price出黎 (例如5件貨就要計5件既total price)
但係我每次loop都會overwrite左個price1
點算?
[ 本帖最後由 silzai 於 2008-11-25 20:14 編輯 ] |