From 8b8ee7116a0768c2c64725fc9dde447780df4131 Mon Sep 17 00:00:00 2001 From: yojjal060 Date: Sun, 4 Oct 2026 13:52:24 +0545 Subject: [PATCH 1/4] new commit with some changes --- Math-Game/Math-Game.slnx | 3 + Math-Game/Math-Game/Classes.cs | 127 +++++++++++++++++++++++++++ Math-Game/Math-Game/Math-Game.csproj | 11 +++ Math-Game/Math-Game/Program.cs | 57 ++++++++++++ 4 files changed, 198 insertions(+) create mode 100644 Math-Game/Math-Game.slnx create mode 100644 Math-Game/Math-Game/Classes.cs create mode 100644 Math-Game/Math-Game/Math-Game.csproj create mode 100644 Math-Game/Math-Game/Program.cs diff --git a/Math-Game/Math-Game.slnx b/Math-Game/Math-Game.slnx new file mode 100644 index 00000000..afd3844c --- /dev/null +++ b/Math-Game/Math-Game.slnx @@ -0,0 +1,3 @@ + + + diff --git a/Math-Game/Math-Game/Classes.cs b/Math-Game/Math-Game/Classes.cs new file mode 100644 index 00000000..bf040bae --- /dev/null +++ b/Math-Game/Math-Game/Classes.cs @@ -0,0 +1,127 @@ +using System; + + +namespace Math_Game +{ + internal class Addition + { + public void Start() + { + Console.WriteLine("How many questions would you like to answer?"); + int numberOfQuestions = int.Parse(Console.ReadLine()); + Random random = new Random(); + int score = 0; + for (int i = 0; i < numberOfQuestions; i++) + { + int num1 = random.Next(1, 100); + int num2 = random.Next(1, 100); + int answer = num1 + num2; + Console.WriteLine($"What is {num1} + {num2}?"); + int userAnswer = int.Parse(Console.ReadLine()); + if (userAnswer == answer) + { + Console.WriteLine("Correct!"); + score++; + } + else + { + Console.WriteLine($"Incorrect. The correct answer is {answer}."); + } + } + Console.WriteLine($"Your score is {score} out of {numberOfQuestions}."); + } + } + + internal class Subtraction + { + public void Start() + { + Console.WriteLine("How many questions would you like to answer?"); + int numberOfQuestions = int.Parse(Console.ReadLine()); + Random random = new Random(); + int score = 0; + for (int i = 0; i < numberOfQuestions; i++) + { + int num1 = random.Next(1, 100); + int num2 = random.Next(1, 100); + int answer = Math.Abs(num1 - num2); + Console.WriteLine($"What is {num1} - {num2}?"); + int userAnswer = int.Parse(Console.ReadLine()); + if (userAnswer == answer) + { + Console.WriteLine("Correct!"); + score++; + } + else + { + Console.WriteLine($"Incorrect. The correct answer is {answer}."); + } + } + Console.WriteLine($"Your score is {score} out of {numberOfQuestions}."); + } + } + + internal class Multiplication + { + public void Start() + { + Console.WriteLine("How many questions would you like to answer?"); + int numberOfQuestions = int.Parse(Console.ReadLine()); + Random random = new Random(); + int score = 0; + for (int i = 0; i < numberOfQuestions; i++) + { + int num1 = random.Next(1, 100); + int num2 = random.Next(1, 100); + int answer = num1 * num2; + Console.WriteLine($"What is {num1} * {num2}?"); + int userAnswer = int.Parse(Console.ReadLine()); + if (userAnswer == answer) + { + Console.WriteLine("Correct!"); + score++; + } + else + { + Console.WriteLine($"Incorrect. The correct answer is {answer}."); + } + } + Console.WriteLine($"Your score is {score} out of {numberOfQuestions}."); + } + } + + internal class Division + { + public void Start() + { + Console.WriteLine("How many questions would you like to answer?"); + int numberOfQuestions = int.Parse(Console.ReadLine()); + Random random = new Random(); + int score = 0; + for (int i = 0; i < numberOfQuestions; i++) + { + int num1, num2; + do + { + num1 = random.Next(1, 100); + num2 = random.Next(1, 100); + } while (num1 % num2 != 0); + + int answer = num1 / num2; + Console.WriteLine($"What is {num1} / {num2}?"); + int userAnswer = int.Parse(Console.ReadLine()); + if (userAnswer == answer) + { + Console.WriteLine("Correct!"); + score++; + } + else + { + Console.WriteLine($"Incorrect. The correct answer is {answer}."); + } + } + Console.WriteLine($"Your score is {score} out of {numberOfQuestions}."); + } + } + +} diff --git a/Math-Game/Math-Game/Math-Game.csproj b/Math-Game/Math-Game/Math-Game.csproj new file mode 100644 index 00000000..50a3b8c4 --- /dev/null +++ b/Math-Game/Math-Game/Math-Game.csproj @@ -0,0 +1,11 @@ + + + + Exe + net10.0 + Math_Game + enable + enable + + + diff --git a/Math-Game/Math-Game/Program.cs b/Math-Game/Math-Game/Program.cs new file mode 100644 index 00000000..5cd1addc --- /dev/null +++ b/Math-Game/Math-Game/Program.cs @@ -0,0 +1,57 @@ +using System; +using Math_Game; + +Console.WriteLine(@" __ __ _ _ _ _ __ __ _ _ ____ _ + \ \ / /__| | ___ ___ _ __ ___ ___ | |_ ___ | |_| |__ ___ | \/ | __ _| |_| |__ / ___| __ _ _ __ ___ ___ | | + \ \ /\ / / _ \ |/ __/ _ \| '_ ` _ \ / _ \ | __/ _ \ | __| '_ \ / _ \ | |\/| |/ _` | __| '_ \| | _ / _` | '_ ` _ \ / _ \ | | + \ V V / __/ | (_| (_) | | | | | | __/ | || (_) | | |_| | | | __/ | | | | (_| | |_| | | | |_| | (_| | | | | | | __/ |_| + \_/\_/ \___|_|\___\___/|_| |_| |_|\___| \__\___/ \__|_| |_|\___| |_| |_|\__,_|\__|_| |_|\____|\__,_|_| |_| |_|\___| (_) +"); + + + + + + +Console.WriteLine("Please Enter your Name"); +string name = Console.ReadLine(); +bool isPlaying = true; +while (isPlaying) +{ + + Console.WriteLine($"Hello, {name}! Let's start the game."); + Console.WriteLine("What Game would you like to play?"); + Console.WriteLine("1. Addition"); + Console.WriteLine("2. Subtraction"); + Console.WriteLine("3. Multiplication"); + Console.WriteLine("4. Division"); + Console.WriteLine("5. Exit"); + + int choice = int.Parse(Console.ReadLine()); + switch (choice) + { + case 1: + Addition addition = new Addition(); + addition.Start(); + break; + case 2: + Subtraction subtraction = new Subtraction(); + subtraction.Start(); + break; + case 3: + Multiplication multiplication = new Multiplication(); + multiplication.Start(); + break; + case 4: + Division division = new Division(); + division.Start(); + break; + case 5: + Console.WriteLine("Thank you for playing!"); + isPlaying = false; + break; + default: + Console.WriteLine("Invalid choice. Please try again."); + break; + } +} \ No newline at end of file From d7d2d52d0427a89a00a461207353a08d84e6128f Mon Sep 17 00:00:00 2001 From: yojjal060 Date: Sun, 4 Oct 2026 16:20:36 +0545 Subject: [PATCH 2/4] added the list game method to track previous game --- Math-Game/Math-Game/Classes.cs | 38 +++++++++++++++++++++++---- Math-Game/Math-Game/Program.cs | 48 ++++++++++++++++++++++------------ 2 files changed, 64 insertions(+), 22 deletions(-) diff --git a/Math-Game/Math-Game/Classes.cs b/Math-Game/Math-Game/Classes.cs index bf040bae..a5b90605 100644 --- a/Math-Game/Math-Game/Classes.cs +++ b/Math-Game/Math-Game/Classes.cs @@ -5,7 +5,7 @@ namespace Math_Game { internal class Addition { - public void Start() + public void Start(List games) { Console.WriteLine("How many questions would you like to answer?"); int numberOfQuestions = int.Parse(Console.ReadLine()); @@ -29,12 +29,16 @@ public void Start() } } Console.WriteLine($"Your score is {score} out of {numberOfQuestions}."); + games.Add($"Addition - score is {score}"); + Console.WriteLine(""); + } + } internal class Subtraction { - public void Start() + public void Start(List games) { Console.WriteLine("How many questions would you like to answer?"); int numberOfQuestions = int.Parse(Console.ReadLine()); @@ -58,12 +62,13 @@ public void Start() } } Console.WriteLine($"Your score is {score} out of {numberOfQuestions}."); + games.Add($"Subtraction - score is {score}"); } } internal class Multiplication { - public void Start() + public void Start(List games) { Console.WriteLine("How many questions would you like to answer?"); int numberOfQuestions = int.Parse(Console.ReadLine()); @@ -87,12 +92,13 @@ public void Start() } } Console.WriteLine($"Your score is {score} out of {numberOfQuestions}."); + games.Add($"Multiplication - score is {score}"); } } internal class Division { - public void Start() + public void Start(List games) { Console.WriteLine("How many questions would you like to answer?"); int numberOfQuestions = int.Parse(Console.ReadLine()); @@ -106,7 +112,7 @@ public void Start() num1 = random.Next(1, 100); num2 = random.Next(1, 100); } while (num1 % num2 != 0); - + int answer = num1 / num2; Console.WriteLine($"What is {num1} / {num2}?"); int userAnswer = int.Parse(Console.ReadLine()); @@ -121,7 +127,29 @@ public void Start() } } Console.WriteLine($"Your score is {score} out of {numberOfQuestions}."); + games.Add($"Division - score is {score}"); + } + } + + internal class PreviousGameScore + { + public void Start(List games) + { + Console.WriteLine("Here are your previous game scores:"); + if (games.Count == 0) + { + Console.WriteLine("No games have been played yet."); + } + else + { + foreach (var game in games) + { + Console.WriteLine(game); + } + } + } + } } diff --git a/Math-Game/Math-Game/Program.cs b/Math-Game/Math-Game/Program.cs index 5cd1addc..36d73d77 100644 --- a/Math-Game/Math-Game/Program.cs +++ b/Math-Game/Math-Game/Program.cs @@ -1,6 +1,7 @@ using System; using Math_Game; + Console.WriteLine(@" __ __ _ _ _ _ __ __ _ _ ____ _ \ \ / /__| | ___ ___ _ __ ___ ___ | |_ ___ | |_| |__ ___ | \/ | __ _| |_| |__ / ___| __ _ _ __ ___ ___ | | \ \ /\ / / _ \ |/ __/ _ \| '_ ` _ \ / _ \ | __/ _ \ | __| '_ \ / _ \ | |\/| |/ _` | __| '_ \| | _ / _` | '_ ` _ \ / _ \ | | @@ -16,6 +17,9 @@ Console.WriteLine("Please Enter your Name"); string name = Console.ReadLine(); bool isPlaying = true; + +var games = new List(); + while (isPlaying) { @@ -25,31 +29,41 @@ Console.WriteLine("2. Subtraction"); Console.WriteLine("3. Multiplication"); Console.WriteLine("4. Division"); - Console.WriteLine("5. Exit"); + Console.WriteLine("5. Previous Game Score"); + Console.WriteLine("6. Exit"); int choice = int.Parse(Console.ReadLine()); switch (choice) { case 1: - Addition addition = new Addition(); - addition.Start(); - break; - case 2: - Subtraction subtraction = new Subtraction(); - subtraction.Start(); - break; - case 3: - Multiplication multiplication = new Multiplication(); - multiplication.Start(); - break; - case 4: - Division division = new Division(); - division.Start(); - break; - case 5: + Addition addition = new Addition(); + addition.Start(games); + break; + case 2: + Subtraction subtraction = new Subtraction(); + subtraction.Start(games); + break; + case 3: + Multiplication multiplication = new Multiplication(); + multiplication.Start(games); + break; + case 4: + Division division = new Division(); + division.Start(games); + break; + + case 5: + PreviousGameScore previousGameScore = new PreviousGameScore(); + previousGameScore.Start(games); + break; + + case 6: Console.WriteLine("Thank you for playing!"); isPlaying = false; break; + + + default: Console.WriteLine("Invalid choice. Please try again."); break; From be4b4c35b398253f0276c56367d3d914618d9131 Mon Sep 17 00:00:00 2001 From: yojjal060 Date: Sun, 4 Oct 2026 16:40:44 +0545 Subject: [PATCH 3/4] console helper for pause and decoratives --- Math-Game/Math-Game/Classes.cs | 19 ++++++++++++++++-- Math-Game/Math-Game/Program.cs | 35 +++++++++++++++++----------------- 2 files changed, 35 insertions(+), 19 deletions(-) diff --git a/Math-Game/Math-Game/Classes.cs b/Math-Game/Math-Game/Classes.cs index a5b90605..d3ef6b0d 100644 --- a/Math-Game/Math-Game/Classes.cs +++ b/Math-Game/Math-Game/Classes.cs @@ -30,7 +30,7 @@ public void Start(List games) } Console.WriteLine($"Your score is {score} out of {numberOfQuestions}."); games.Add($"Addition - score is {score}"); - Console.WriteLine(""); + ConsoleHelper.Pause(); } @@ -63,6 +63,7 @@ public void Start(List games) } Console.WriteLine($"Your score is {score} out of {numberOfQuestions}."); games.Add($"Subtraction - score is {score}"); + ConsoleHelper.Pause(); } } @@ -93,6 +94,7 @@ public void Start(List games) } Console.WriteLine($"Your score is {score} out of {numberOfQuestions}."); games.Add($"Multiplication - score is {score}"); + ConsoleHelper.Pause(); } } @@ -127,7 +129,8 @@ public void Start(List games) } } Console.WriteLine($"Your score is {score} out of {numberOfQuestions}."); - games.Add($"Division - score is {score}"); + games.Add($"{DateTime.Now} Division - score is {score}"); + ConsoleHelper.Pause(); } } @@ -147,9 +150,21 @@ public void Start(List games) Console.WriteLine(game); } } + ConsoleHelper.Pause(); } } + internal static class ConsoleHelper + { + public static void Pause() + { + Console.WriteLine(); + Console.WriteLine("Press any key to return to the main menu..."); + Console.ReadKey(true); + Console.Clear(); + } + } + } diff --git a/Math-Game/Math-Game/Program.cs b/Math-Game/Math-Game/Program.cs index 36d73d77..81f81991 100644 --- a/Math-Game/Math-Game/Program.cs +++ b/Math-Game/Math-Game/Program.cs @@ -39,23 +39,23 @@ Addition addition = new Addition(); addition.Start(games); break; - case 2: - Subtraction subtraction = new Subtraction(); - subtraction.Start(games); - break; - case 3: - Multiplication multiplication = new Multiplication(); - multiplication.Start(games); - break; - case 4: - Division division = new Division(); - division.Start(games); - break; + case 2: + Subtraction subtraction = new Subtraction(); + subtraction.Start(games); + break; + case 3: + Multiplication multiplication = new Multiplication(); + multiplication.Start(games); + break; + case 4: + Division division = new Division(); + division.Start(games); + break; - case 5: - PreviousGameScore previousGameScore = new PreviousGameScore(); - previousGameScore.Start(games); - break; + case 5: + PreviousGameScore previousGameScore = new PreviousGameScore(); + previousGameScore.Start(games); + break; case 6: Console.WriteLine("Thank you for playing!"); @@ -66,6 +66,7 @@ default: Console.WriteLine("Invalid choice. Please try again."); + ConsoleHelper.Pause(); break; } -} \ No newline at end of file +} From 49e52ee73beee096bdeb60aef74e861a9286af54 Mon Sep 17 00:00:00 2001 From: yojjal060 Date: Sun, 4 Oct 2026 17:16:05 +0545 Subject: [PATCH 4/4] some changes --- Math-Game/Math-Game/Classes.cs | 46 ++++++++++++++++++++++++++-------- Math-Game/Math-Game/Program.cs | 19 ++++++++++++-- 2 files changed, 52 insertions(+), 13 deletions(-) diff --git a/Math-Game/Math-Game/Classes.cs b/Math-Game/Math-Game/Classes.cs index d3ef6b0d..056143dc 100644 --- a/Math-Game/Math-Game/Classes.cs +++ b/Math-Game/Math-Game/Classes.cs @@ -7,8 +7,14 @@ internal class Addition { public void Start(List games) { - Console.WriteLine("How many questions would you like to answer?"); + Console.WriteLine("How many questions would you like to answer? (It must be 5 or greater than 5)"); int numberOfQuestions = int.Parse(Console.ReadLine()); + if(numberOfQuestions < 5) + { + Console.WriteLine("You must enter a number that is 5 or greater than 5."); + ConsoleHelper.Pause(); + return; + } Random random = new Random(); int score = 0; for (int i = 0; i < numberOfQuestions; i++) @@ -29,7 +35,7 @@ public void Start(List games) } } Console.WriteLine($"Your score is {score} out of {numberOfQuestions}."); - games.Add($"Addition - score is {score}"); + games.Add($"Addition - score is {score}/{numberOfQuestions}"); ConsoleHelper.Pause(); } @@ -40,15 +46,21 @@ internal class Subtraction { public void Start(List games) { - Console.WriteLine("How many questions would you like to answer?"); + Console.WriteLine("How many questions would you like to answer? (It must be 5 or greater than 5)"); int numberOfQuestions = int.Parse(Console.ReadLine()); + if (numberOfQuestions < 5) + { + Console.WriteLine("You must enter a number that is 5 or greater than 5."); + ConsoleHelper.Pause(); + return; + } Random random = new Random(); int score = 0; for (int i = 0; i < numberOfQuestions; i++) { int num1 = random.Next(1, 100); int num2 = random.Next(1, 100); - int answer = Math.Abs(num1 - num2); + int answer = (num1 - num2); Console.WriteLine($"What is {num1} - {num2}?"); int userAnswer = int.Parse(Console.ReadLine()); if (userAnswer == answer) @@ -62,7 +74,7 @@ public void Start(List games) } } Console.WriteLine($"Your score is {score} out of {numberOfQuestions}."); - games.Add($"Subtraction - score is {score}"); + games.Add($"Subtraction - score is {score}/{numberOfQuestions}"); ConsoleHelper.Pause(); } } @@ -71,8 +83,14 @@ internal class Multiplication { public void Start(List games) { - Console.WriteLine("How many questions would you like to answer?"); + Console.WriteLine("How many questions would you like to answer? (It must be 5 or greater than 5)"); int numberOfQuestions = int.Parse(Console.ReadLine()); + if (numberOfQuestions < 5) + { + Console.WriteLine("You must enter a number that is 5 or greater than 5."); + ConsoleHelper.Pause(); + return; + } Random random = new Random(); int score = 0; for (int i = 0; i < numberOfQuestions; i++) @@ -93,7 +111,7 @@ public void Start(List games) } } Console.WriteLine($"Your score is {score} out of {numberOfQuestions}."); - games.Add($"Multiplication - score is {score}"); + games.Add($"Multiplication - score is {score}/{numberOfQuestions}"); ConsoleHelper.Pause(); } } @@ -102,8 +120,14 @@ internal class Division { public void Start(List games) { - Console.WriteLine("How many questions would you like to answer?"); + Console.WriteLine("How many questions would you like to answer? (It must be 5 or greater than 5)"); int numberOfQuestions = int.Parse(Console.ReadLine()); + if (numberOfQuestions < 5) + { + Console.WriteLine("You must enter a number that is 5 or greater than 5."); + ConsoleHelper.Pause(); + return; + } Random random = new Random(); int score = 0; for (int i = 0; i < numberOfQuestions; i++) @@ -111,8 +135,8 @@ public void Start(List games) int num1, num2; do { - num1 = random.Next(1, 100); - num2 = random.Next(1, 100); + num1 = random.Next(1, 101); + num2 = random.Next(1, 101); } while (num1 % num2 != 0); int answer = num1 / num2; @@ -129,7 +153,7 @@ public void Start(List games) } } Console.WriteLine($"Your score is {score} out of {numberOfQuestions}."); - games.Add($"{DateTime.Now} Division - score is {score}"); + games.Add($" Division - score is {score}/{numberOfQuestions}"); ConsoleHelper.Pause(); } } diff --git a/Math-Game/Math-Game/Program.cs b/Math-Game/Math-Game/Program.cs index 81f81991..796b11b4 100644 --- a/Math-Game/Math-Game/Program.cs +++ b/Math-Game/Math-Game/Program.cs @@ -32,9 +32,24 @@ Console.WriteLine("5. Previous Game Score"); Console.WriteLine("6. Exit"); - int choice = int.Parse(Console.ReadLine()); - switch (choice) + int choice; + while (true) { + string rawInput = Console.ReadLine()?.Trim(); + if (string.IsNullOrWhiteSpace(rawInput)) + { + Console.WriteLine("Input was empty. Please enter a number between 1 and 6."); + continue; + } + if (!int.TryParse(rawInput, out choice) || choice < 1 || choice > 6) + { + Console.WriteLine("Invalid selection. Please enter a number between 1 and 6."); + continue; + } + break; + } + switch (choice) + { case 1: Addition addition = new Addition(); addition.Start(games);