using System; namespace PS2_Q1 { // // Problem Set 2, Question 1 // Written by Paul Hudak // Sept 25, 2006 // class Class1 { // // Program Design Exercise 11 in Chapter 3 // [STAThread] static void Main(string[] args) { // get costs of food items from user double cerealA = GetPrice("box of cereal","A"); double milkA = GetPrice("quart of milk","A"); double cerealB = GetPrice("box of cereal","B"); double milkB = GetPrice("quart of milk","B"); // compute total costs for each store double costA = 3*cerealA + 2*milkA; double costB = 3*cerealB + 2*milkB; // display total cost of cheapest store if (costA <= costB) OutputResult("A",costA); else OutputResult("B",costB); } public static double GetPrice(string food, string store) { Console.Write("What is the price of a {0} at store {1}? ", food, store); return double.Parse(Console.ReadLine()); } public static void OutputResult(string store, double cost) { Console.WriteLine("\nStore {0} is the least expensive: {1:C} total.\n", store, cost); } } }