Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>you need a while encapsulating your main logic. this while would be exited by, say, typing q, otherwise it would loop through your current main again.</p> <pre><code>class Program { static void Main(string[] args) { List&lt;Car&gt; myCars = new List&lt;Car&gt;() { new Car() { Make="BMW", Model="550i", Color=CarColor.Blue, StickerPrice=55000, Year=2009 }, new Car() { Make="Toyota", Model="4Runner", Color=CarColor.White, StickerPrice=35000, Year=2010 }, new Car() { Make="BMW", Model="745li", Color=CarColor.Black, StickerPrice=75000, Year=2008 }, new Car() { Make="Ford", Model="Escape", Color=CarColor.White, StickerPrice=28000, Year=2008 }, new Car() { Make="BMW", Model="550i", Color=CarColor.Black, StickerPrice=57000, Year=2010 } }; bool ohPleaseLetMeDoItAgain = true; while (ohPleaseLetMeDoItAgain) { Console.WriteLine("Type \"all\" to see total value of all cars"); Console.WriteLine("Type \"bmw\" to see total value of all bmws"); Console.WriteLine("Type \"toyota\" to see total value of all Toyotas"); Console.WriteLine("Type \"ford\" to see total value of all Fords"); Console.WriteLine("Type \"q\" to quit"); string userValue = Console.ReadLine(); if (userValue == "all") { var _orderedCars = myCars.OrderByDescending(p =&gt; p.Year); foreach (var car in _orderedCars) { Console.WriteLine("{0} {1} - {2} - {3:C}", car.Make, car.Model, car.Year, car.StickerPrice); } var sum = _orderedCars.Sum(p =&gt; p.StickerPrice); Console.WriteLine("{0:C}", sum); } else if (userValue == "bmw") { var _bmws = myCars.Where(car =&gt; car.Make == "BMW"); foreach (var car in _bmws) { Console.WriteLine("{0} {1} - {2}- {3:C}", car.Make, car.Model, car.Year, car.StickerPrice); } var sum = _bmws.Sum(p =&gt; p.StickerPrice); Console.WriteLine("{0:C}", sum); } else if (userValue == "toyota") { var _toyotaCars = myCars.Where(car =&gt; car.Make == "Toyota"); foreach (var car in _toyotaCars) { Console.WriteLine("{0} {1} - {2} - {3:C}", car.Make, car.Model, car.Year, car.StickerPrice); } var sum = _toyotaCars.Sum(p =&gt; p.StickerPrice); Console.WriteLine("{0:C}", sum); } else if (userValue == "ford") { var _fordCars = myCars.Where(car =&gt; car.Make == "Ford"); foreach (var car in _fordCars) { Console.WriteLine("{0} {1} - {2} - {3:C}", car.Make, car.Model, car.Year, car.StickerPrice); } var sum = _fordCars.Sum(p =&gt; p.StickerPrice); Console.WriteLine("{0:C}", sum); } else { ohPleaseLetMeDoItAgain = !userValue.Equals("q"); } } } class Car { public string Make { get; set; } public string Model { get; set; } public int Year { get; set; } public double StickerPrice { get; set; } public CarColor Color { get; set; } } enum CarColor { White, Black, Red, Blue, Yellow } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload