// CSE 142, Spring 2010, Marty Stepp // This is an improved version of the "Receipt" program from week 2. // Now it is more flexible because it uses the Scanner and a cumulative sum. // See also the Receipt3 file for an improved version that uses methods. import java.util.*; // for Scanner public class Receipt2 { public static void main(String[] args) { System.out.print("How many people ate? "); Scanner console = new Scanner(System.in); int people = console.nextInt(); // cumulative sum of each person's meal cost double subtotal = 0.00; for (int i = 1; i <= people; i++) { System.out.print("Person #" + i + ": How much did your dinner cost? "); double cost = console.nextDouble(); subtotal = subtotal + cost; } System.out.printf("Subtotal = $%.2f\n", subtotal); } }