From 5ea0c1bd54104a587aafb9d085b5262a0288c178 Mon Sep 17 00:00:00 2001 From: "jason.zhu" Date: Mon, 22 Feb 2021 00:12:35 +0000 Subject: [PATCH] Finished Challenge: Taking User Input from Console; By myself --- gradebook/src/GradeBook/Program.cs | 31 ++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/gradebook/src/GradeBook/Program.cs b/gradebook/src/GradeBook/Program.cs index 9ac665c..935521e 100644 --- a/gradebook/src/GradeBook/Program.cs +++ b/gradebook/src/GradeBook/Program.cs @@ -8,15 +8,34 @@ namespace GradeBook static void Main(string[] args) { - var book = new Book("Scott's Grade Book"); - book.AddGrade(89.1); - book.AddGrade(90.5); - book.AddGrade(87.2); - + // var book = new Book("Scott's Grade Book"); + // book.AddGrade(89.1); + // book.AddGrade(90.5); + // book.AddGrade(87.2); + + var book = new Book("Jason's Grade Book"); + string input; + + bool if_continue = true; + while (if_continue) + { + Console.WriteLine("Give input: "); + input = Console.ReadLine(); + if (input == "Q" || input == "q") + { + Console.WriteLine("Receiving termination signal; Termiate program"); + break; + } else + { + Console.WriteLine($"Received: {input}"); + book.AddGrade(Convert.ToDouble(input)); + } + } + var stats = book.GetStatistics(); Console.WriteLine($"The lowest grade is {stats.lowGrade}"); - Console.WriteLine($"The highest grade is {stats.highGrade}"); + Console.WriteLine($"The highesst grade is {stats.highGrade}"); Console.WriteLine($"The average grade is {stats.Average:N1}"); } }