public static void Run_Fancy() { var scores = new List <double>(); for (double s = ConsoleRead.ReadDouble(); s != -1; s = ConsoleRead.ReadDouble()) { scores.Add(s); } double avg = scores.Average(); double threshold = 0.0001; for (int i = 0; i < scores.Count; i++) { string pos = ""; var color = ConsoleColor.Yellow; if (scores[i] - threshold > avg) { pos = "ABOVE "; color = ConsoleColor.Green; } else if (scores[i] + threshold < avg) { pos = "BELOW "; color = ConsoleColor.Red; } ConsoleWrite.WriteLinesColored(color, $"{scores[i]:f2} {pos}AVERAGE"); } }
public static void Run() { var scores = new List <double>(); for (double s = ConsoleRead.ReadDouble(); s != -1; s = ConsoleRead.ReadDouble()) { scores.Add(s); } double avg = scores.Average(); double threshold = 0.0001;//This is to avoid floating point errors for (int i = 0; i < scores.Count; i++) { if (scores[i] - threshold > avg) { Console.WriteLine($"{scores[i]:f2} ABOVE AVERAGE"); } else if (scores[i] + threshold < avg) { Console.WriteLine($"{scores[i]:f2} BELOW AVERAGE"); } else { Console.WriteLine($"{scores[i]:f2} AVERAGE"); } } }
public static void Run() { Console.WriteLine("Enter item name"); string itemName = Console.ReadLine(); Console.WriteLine("Enter item price"); double itemPrice = ConsoleRead.ReadDouble(); Console.WriteLine("Enter quantity"); int quant = ConsoleRead.ReadInt32(); Console.WriteLine($"{quant} x {itemName} @ {itemPrice:c2} Total: {itemPrice * quant:c2}"); }
public static void Run() { string itemName = Console.ReadLine(); double itemPrice = ConsoleRead.ReadDouble(); int quant = ConsoleRead.ReadInt32(); Console.WriteLine($"{quant} x {itemName} @ {itemPrice:c2}"); if (quant < 10) { Console.WriteLine($"Total: { itemPrice* quant:c2}"); } else { Console.WriteLine($"Subtotal: { itemPrice * quant:c2}"); Console.WriteLine($"-10% Discount: {itemPrice * quant * 0.1:c2}");//Yes, you can store this in a variable and subtract it in the next step, but there's not really any need Console.WriteLine($"Total: { itemPrice * quant * 0.9:c2}"); } }