From c57ac0442859c90822c8d91aa0842decdf90f78d Mon Sep 17 00:00:00 2001 From: AlexRamos_ Date: Mon, 23 Mar 2026 10:08:44 -0600 Subject: [PATCH 1/5] Setup - Project --- MathGame/MathGame.sln | 25 +++ MathGame/MathGame/MathGame.csproj | 10 ++ MathGame/MathGame/Program.cs | 277 ++++++++++++++++++++++++++++++ 3 files changed, 312 insertions(+) create mode 100644 MathGame/MathGame.sln create mode 100644 MathGame/MathGame/MathGame.csproj create mode 100644 MathGame/MathGame/Program.cs diff --git a/MathGame/MathGame.sln b/MathGame/MathGame.sln new file mode 100644 index 00000000..02628b79 --- /dev/null +++ b/MathGame/MathGame.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.14.37111.16 d17.14 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MathGame", "MathGame\MathGame.csproj", "{1117B72E-7283-4EFF-BFD4-7D38D33D2AFF}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {1117B72E-7283-4EFF-BFD4-7D38D33D2AFF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1117B72E-7283-4EFF-BFD4-7D38D33D2AFF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1117B72E-7283-4EFF-BFD4-7D38D33D2AFF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1117B72E-7283-4EFF-BFD4-7D38D33D2AFF}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {736DC4EB-5F65-49AE-930E-B140DF9CF4AD} + EndGlobalSection +EndGlobal diff --git a/MathGame/MathGame/MathGame.csproj b/MathGame/MathGame/MathGame.csproj new file mode 100644 index 00000000..2150e379 --- /dev/null +++ b/MathGame/MathGame/MathGame.csproj @@ -0,0 +1,10 @@ + + + + Exe + net8.0 + enable + enable + + + diff --git a/MathGame/MathGame/Program.cs b/MathGame/MathGame/Program.cs new file mode 100644 index 00000000..d99f96c6 --- /dev/null +++ b/MathGame/MathGame/Program.cs @@ -0,0 +1,277 @@ + +string? userInput; +int questionsAsked = 0; +int maxQuestionAsked = 5; +int correctAnswers = 0; +List gamesPlayed = []; +int userResult; +int numberOne; +int numberTwo; +int result; + +do +{ + Console.Clear(); + + Console.WriteLine("Hello, Welcome to Math Game!\n"); + + Console.WriteLine("- 1 - Addition operation."); + Console.WriteLine("- 2 - Addition subtraction."); + Console.WriteLine("- 3 - Addition division."); + Console.WriteLine("- 4 - Addition multiplication."); + Console.WriteLine("- 5 - Review results.\n"); + + Console.WriteLine("Please type a number to choose an option from the menu: "); + + userInput = Console.ReadLine().Trim(); + + switch (userInput) + { + case "1": + if (CheckStatusGame()) + { + break; + } + + numberOne = GetRandomNumber(10); + numberTwo = GetRandomNumber(10); + + result = numberOne + numberTwo; + + Console.WriteLine("\nWhat is the result of the following operation?"); + Console.WriteLine($"\n{numberOne} + {numberTwo} = ? \n"); + userInput = Console.ReadLine().Trim(); + + try + { + userResult = Convert.ToInt32(userInput); + } + catch + { + Console.WriteLine("\nInvalid input!"); + Console.WriteLine("\nPress the Enter key to continue."); + Console.ReadLine(); + break; + } + + if (userResult == result) + { + Console.WriteLine("\nCorrect!"); + questionsAsked++; + correctAnswers++; + } + else + { + Console.WriteLine("\nWrong answer!"); + questionsAsked++; + correctAnswers--; + } + + Console.WriteLine("\nPress the Enter key to continue."); + Console.ReadLine(); + break; + + case "2": + if (CheckStatusGame()) + { + break; + } + + numberOne = GetRandomNumber(10); + numberTwo = GetRandomNumber(10); + + result = numberOne - numberTwo; + + Console.WriteLine("\nWhat is the result of the following operation?"); + Console.WriteLine($"\n{numberOne} - {numberTwo} = ? \n"); + userInput = Console.ReadLine().Trim(); + + try + { + userResult = Convert.ToInt32(userInput); + } + catch + { + Console.WriteLine("\nInvalid input!"); + Console.WriteLine("\nPress the Enter key to continue."); + Console.ReadLine(); + break; + } + + if (userResult == Math.Abs(result)) + { + Console.WriteLine("\nCorrect!"); + questionsAsked++; + correctAnswers++; + } + else + { + Console.WriteLine("\nWrong answer!"); + questionsAsked++; + correctAnswers--; + } + + Console.WriteLine("\nPress the Enter key to continue."); + Console.ReadLine(); + break; + + case "3": + if (CheckStatusGame()) + { + break; + } + + numberOne = GetRandomNumber(100); + numberTwo = 2; + + result = numberOne % numberTwo; + + if (result == 0) + { + result = numberOne / numberTwo; + } + else + { + while (result != 0) + { + numberOne = GetRandomNumber(100); + + result = numberOne % numberTwo; + } + + result = numberOne / numberTwo; + } + + Console.WriteLine("\nWhat is the result of the following operation?"); + Console.WriteLine($"\n{numberOne} / {numberTwo} = ? \n"); + userInput = Console.ReadLine().Trim(); + + try + { + userResult = Convert.ToInt32(userInput); + } + catch + { + Console.WriteLine("\nInvalid input!"); + Console.WriteLine("\nPress the Enter key to continue."); + Console.ReadLine(); + break; + } + + if (userResult == result) + { + Console.WriteLine("\nCorrect!"); + questionsAsked++; + correctAnswers++; + } + else + { + Console.WriteLine("\nWrong answer!"); + questionsAsked++; + correctAnswers--; + } + + Console.WriteLine("\nYou have choose division."); + + Console.WriteLine("\nPress the Enter key to continue."); + Console.ReadLine(); + break; + + case "4": + if (CheckStatusGame()) + { + break; + } + + numberOne = GetRandomNumber(10); + numberTwo = GetRandomNumber(10); + + result = numberOne * numberTwo; + + Console.WriteLine("\nWhat is the result of the following operation?"); + Console.WriteLine($"\n{numberOne} x {numberTwo} = ? \n"); + userInput = Console.ReadLine().Trim(); + + try + { + userResult = Convert.ToInt32(userInput); + } + catch + { + Console.WriteLine("\nInvalid input!"); + Console.WriteLine("\nPress the Enter key to continue."); + Console.ReadLine(); + break; + } + + if (userResult == result) + { + Console.WriteLine("\nCorrect!"); + questionsAsked++; + correctAnswers++; + } + else + { + Console.WriteLine("\nWrong answer!"); + questionsAsked++; + correctAnswers--; + } + + Console.WriteLine("\nYou have choose multiplication."); + + Console.WriteLine("\nPress the Enter key to continue."); + Console.ReadLine(); + break; + + case "5": + + Console.WriteLine("\nReview your games!\n"); + + if (gamesPlayed.Count() == 0) + { + Console.WriteLine("You have not complete any game yet!"); + Console.WriteLine("\nPress the Enter key to continue."); + Console.ReadLine(); + break; + } + + foreach (var game in gamesPlayed) + { + Console.WriteLine($"{game}"); + } + + Console.WriteLine("\nPress the Enter key to continue."); + Console.ReadLine(); + break; + + default: + break; + } +} +while (userInput != "exit"); + +int GetRandomNumber(int number) +{ + Random randomNumber = new(); + return randomNumber.Next(number); +} + +bool CheckStatusGame() +{ + if (questionsAsked == maxQuestionAsked) + { + gamesPlayed.Add($"You got {correctAnswers}/{maxQuestionAsked} correct answers!"); + + Console.WriteLine("\nGame over!\n"); + Console.WriteLine($"Here are your results: {correctAnswers}/{maxQuestionAsked}"); + Console.WriteLine("\nPress the Enter key to play a new game."); + Console.ReadLine(); + + correctAnswers = 0; + questionsAsked = 0; + + return true; + } + + return false; +} From ab065963825968fec277148c10e5f4c9f8f7ee8d Mon Sep 17 00:00:00 2001 From: AlexRamos_ Date: Thu, 26 Mar 2026 12:13:06 -0600 Subject: [PATCH 2/5] Monolithic - Update --- MathGame/MathGame/Program.cs | 469 +++++++++++++++++++++-------------- 1 file changed, 287 insertions(+), 182 deletions(-) diff --git a/MathGame/MathGame/Program.cs b/MathGame/MathGame/Program.cs index d99f96c6..1afeae48 100644 --- a/MathGame/MathGame/Program.cs +++ b/MathGame/MathGame/Program.cs @@ -1,27 +1,44 @@ - +// Math Game Project + +using System.Diagnostics; + string? userInput; + int questionsAsked = 0; int maxQuestionAsked = 5; int correctAnswers = 0; + +Stopwatch stopwatch = new(); + List gamesPlayed = []; -int userResult; -int numberOne; -int numberTwo; -int result; + +bool isChronometer = false; +int difficulty = 10; +int userResult = 0; +int numberOne = 0; +int numberTwo = 0; +int result = 0; + do { Console.Clear(); - Console.WriteLine("Hello, Welcome to Math Game!\n"); + Console.WriteLine("Welcome to Math Game!\n"); Console.WriteLine("- 1 - Addition operation."); - Console.WriteLine("- 2 - Addition subtraction."); - Console.WriteLine("- 3 - Addition division."); - Console.WriteLine("- 4 - Addition multiplication."); - Console.WriteLine("- 5 - Review results.\n"); + Console.WriteLine("- 2 - Subtraction operation."); + Console.WriteLine("- 3 - Division operation."); + Console.WriteLine("- 4 - Multiplication operation."); + Console.WriteLine("- 5 - Random Game."); + Console.WriteLine("- 6 - Change the difficulty."); + Console.WriteLine("- 7 - Review results."); - Console.WriteLine("Please type a number to choose an option from the menu: "); + DisplayDifficulty(); + + CheckChronometerStatus(); + + Console.WriteLine("Please type a number to choose an option from the menu: (exit)"); userInput = Console.ReadLine().Trim(); @@ -32,43 +49,7 @@ { break; } - - numberOne = GetRandomNumber(10); - numberTwo = GetRandomNumber(10); - - result = numberOne + numberTwo; - - Console.WriteLine("\nWhat is the result of the following operation?"); - Console.WriteLine($"\n{numberOne} + {numberTwo} = ? \n"); - userInput = Console.ReadLine().Trim(); - - try - { - userResult = Convert.ToInt32(userInput); - } - catch - { - Console.WriteLine("\nInvalid input!"); - Console.WriteLine("\nPress the Enter key to continue."); - Console.ReadLine(); - break; - } - - if (userResult == result) - { - Console.WriteLine("\nCorrect!"); - questionsAsked++; - correctAnswers++; - } - else - { - Console.WriteLine("\nWrong answer!"); - questionsAsked++; - correctAnswers--; - } - - Console.WriteLine("\nPress the Enter key to continue."); - Console.ReadLine(); + SumOperation(); break; case "2": @@ -76,43 +57,7 @@ { break; } - - numberOne = GetRandomNumber(10); - numberTwo = GetRandomNumber(10); - - result = numberOne - numberTwo; - - Console.WriteLine("\nWhat is the result of the following operation?"); - Console.WriteLine($"\n{numberOne} - {numberTwo} = ? \n"); - userInput = Console.ReadLine().Trim(); - - try - { - userResult = Convert.ToInt32(userInput); - } - catch - { - Console.WriteLine("\nInvalid input!"); - Console.WriteLine("\nPress the Enter key to continue."); - Console.ReadLine(); - break; - } - - if (userResult == Math.Abs(result)) - { - Console.WriteLine("\nCorrect!"); - questionsAsked++; - correctAnswers++; - } - else - { - Console.WriteLine("\nWrong answer!"); - questionsAsked++; - correctAnswers--; - } - - Console.WriteLine("\nPress the Enter key to continue."); - Console.ReadLine(); + SubOperation(); break; case "3": @@ -120,61 +65,7 @@ { break; } - - numberOne = GetRandomNumber(100); - numberTwo = 2; - - result = numberOne % numberTwo; - - if (result == 0) - { - result = numberOne / numberTwo; - } - else - { - while (result != 0) - { - numberOne = GetRandomNumber(100); - - result = numberOne % numberTwo; - } - - result = numberOne / numberTwo; - } - - Console.WriteLine("\nWhat is the result of the following operation?"); - Console.WriteLine($"\n{numberOne} / {numberTwo} = ? \n"); - userInput = Console.ReadLine().Trim(); - - try - { - userResult = Convert.ToInt32(userInput); - } - catch - { - Console.WriteLine("\nInvalid input!"); - Console.WriteLine("\nPress the Enter key to continue."); - Console.ReadLine(); - break; - } - - if (userResult == result) - { - Console.WriteLine("\nCorrect!"); - questionsAsked++; - correctAnswers++; - } - else - { - Console.WriteLine("\nWrong answer!"); - questionsAsked++; - correctAnswers--; - } - - Console.WriteLine("\nYou have choose division."); - - Console.WriteLine("\nPress the Enter key to continue."); - Console.ReadLine(); + DivOperation(); break; case "4": @@ -182,54 +73,24 @@ { break; } + MultOperation(); + break; - numberOne = GetRandomNumber(10); - numberTwo = GetRandomNumber(10); - - result = numberOne * numberTwo; - - Console.WriteLine("\nWhat is the result of the following operation?"); - Console.WriteLine($"\n{numberOne} x {numberTwo} = ? \n"); - userInput = Console.ReadLine().Trim(); - - try - { - userResult = Convert.ToInt32(userInput); - } - catch - { - Console.WriteLine("\nInvalid input!"); - Console.WriteLine("\nPress the Enter key to continue."); - Console.ReadLine(); - break; - } - - if (userResult == result) - { - Console.WriteLine("\nCorrect!"); - questionsAsked++; - correctAnswers++; - } - else - { - Console.WriteLine("\nWrong answer!"); - questionsAsked++; - correctAnswers--; - } - - Console.WriteLine("\nYou have choose multiplication."); + case "5": + PlayRandomGame(); + break; - Console.WriteLine("\nPress the Enter key to continue."); - Console.ReadLine(); + case "6": + ModifyDifficulty(); break; - case "5": + case "7": Console.WriteLine("\nReview your games!\n"); - if (gamesPlayed.Count() == 0) + if (gamesPlayed.Count == 0) { - Console.WriteLine("You have not complete any game yet!"); + Console.WriteLine("You haven't finished any games yet!"); Console.WriteLine("\nPress the Enter key to continue."); Console.ReadLine(); break; @@ -250,28 +111,272 @@ } while (userInput != "exit"); + int GetRandomNumber(int number) { Random randomNumber = new(); return randomNumber.Next(number); } + bool CheckStatusGame() { if (questionsAsked == maxQuestionAsked) { - gamesPlayed.Add($"You got {correctAnswers}/{maxQuestionAsked} correct answers!"); + TimeSpan timeSpan = stopwatch.Elapsed; + + string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", timeSpan.Hours, timeSpan.TotalMinutes, timeSpan.Seconds, timeSpan.Milliseconds / 10); + + gamesPlayed.Add($"You got {correctAnswers}/{maxQuestionAsked} correct answers! - Time: {elapsedTime}"); Console.WriteLine("\nGame over!\n"); Console.WriteLine($"Here are your results: {correctAnswers}/{maxQuestionAsked}"); + Console.WriteLine($"You complete the game under: {elapsedTime}"); Console.WriteLine("\nPress the Enter key to play a new game."); - Console.ReadLine(); correctAnswers = 0; questionsAsked = 0; + stopwatch.Reset(); + isChronometer = false; + + Console.ReadLine(); + return true; } return false; } + + +void CheckQuestion(int userAnswer, int operationResult) +{ + if (userAnswer == operationResult) + { + Console.WriteLine("\nCorrect!"); + questionsAsked++; + correctAnswers++; + } + else + { + Console.WriteLine("\nWrong answer!"); + questionsAsked++; + } + + Console.WriteLine("\nPress the Enter key to continue."); + Console.ReadLine(); +} + + +int DisplayOperation(char charOperation, int valueOne, int valueTwo) +{ + int parsedInput = 0; + + do + { + Console.Clear(); + Console.WriteLine("\nWhat is the result of the following operation?"); + Console.WriteLine($"\n{valueOne} {charOperation} {valueTwo} = ? \n"); + userInput = Console.ReadLine().Trim(); + } + while (int.TryParse(userInput, out parsedInput) == false); + + return parsedInput; +} + + +void SumOperation() +{ + numberOne = GetRandomNumber(difficulty); + numberTwo = GetRandomNumber(difficulty); + + result = numberOne + numberTwo; + + userResult = DisplayOperation('+', numberOne, numberTwo); + + CheckQuestion(userResult, result); +} + + +void SubOperation() +{ + numberOne = GetRandomNumber(difficulty); + numberTwo = GetRandomNumber(difficulty); + + result = Math.Abs(numberOne - numberTwo); + + userResult = DisplayOperation('-', numberOne, numberTwo); + + CheckQuestion(userResult, result); +} + + +void DivOperation() +{ + numberOne = GetRandomNumber(difficulty); + numberTwo = 2; + + result = numberOne % numberTwo; + + if (result == 0) + { + result = numberOne / numberTwo; + } + else + { + while (result != 0) + { + numberOne = GetRandomNumber(difficulty); + + result = numberOne % numberTwo; + } + + result = numberOne / numberTwo; + } + + userResult = DisplayOperation('/', numberOne, numberTwo); + + CheckQuestion(userResult, result); +} + +void MultOperation() +{ + numberOne = GetRandomNumber(difficulty); + numberTwo = GetRandomNumber(difficulty); + + result = numberOne * numberTwo; + + userResult = DisplayOperation('x', numberOne, numberTwo); + + CheckQuestion(userResult, result); +} + +void PlayRandomGame() +{ + do + { + Console.WriteLine("\nDo you want to play a random game? Y/N"); + userInput = Console.ReadLine().ToLower().Trim(); + } + while (userInput != "y" && userInput != "n"); + + if (userInput.Equals("y")) + { + correctAnswers = 0; + questionsAsked = 0; + + CheckChronometerStatus(); + + for (int i = 0; i < maxQuestionAsked; i++) + { + int index = GetRandomNumber(4); + + switch (index) + { + case 0: + SumOperation(); + break; + + case 1: + SubOperation(); + break; + + case 2: + DivOperation(); + break; + + case 3: + MultOperation(); + break; + + default: + break; + } + } + + Console.Clear(); + CheckStatusGame(); + + } + else + { + Console.WriteLine("\nYou cancel the game."); + Console.WriteLine("\nPress the Enter key to continue."); + Console.ReadLine(); + } +} + + +void ModifyDifficulty() +{ + Console.Clear(); + + Console.WriteLine("\nProgression level\n"); + + Console.WriteLine("- 1 - Easy Level"); + Console.WriteLine("- 2 - Medium Level"); + Console.WriteLine("- 3 - Hard Level"); + + DisplayDifficulty(); + + Console.WriteLine("Type \"back\" to go back to main menu"); + + do + { + Console.WriteLine("\nChoose an option from the menu\n"); + userInput = Console.ReadLine().Trim(); + + switch (userInput) + { + + case "1": + Console.WriteLine("\nEasy level setted!"); + difficulty = 10; + Console.WriteLine("\nPress the Enter key to continue."); + Console.ReadLine(); + return; + + case "2": + Console.WriteLine("\nMedium level setted!"); + difficulty = 100; + Console.WriteLine("\nPress the Enter key to continue."); + Console.ReadLine(); + return; + + case "3": + Console.WriteLine("\nHard level setted!"); + difficulty = 1000; + Console.WriteLine("\nPress the Enter key to continue."); + Console.ReadLine(); + return; + } + } + while (userInput != "back"); +} + +void DisplayDifficulty() +{ + switch (difficulty) + { + case 10: + Console.WriteLine($"\nCurrent level of difficulty is Easy.\n"); + break; + + case 100: + Console.WriteLine($"\nCurrent level of difficulty is Medium.\n"); + break; + + case 1000: + Console.WriteLine($"\nCurrent level of difficulty is Hard.\n"); + break; + } +} + +void CheckChronometerStatus() +{ + if (!isChronometer) + { + stopwatch.Start(); + isChronometer = true; + } +} \ No newline at end of file From 197c8cd8830b023ac3223eaf128a5581a963aaed Mon Sep 17 00:00:00 2001 From: AlexRamos_ Date: Thu, 26 Mar 2026 17:20:45 -0600 Subject: [PATCH 3/5] Fixes on operation methods --- MathGame/MathGame/Program.cs | 64 +++++++++++++++++------------------- 1 file changed, 30 insertions(+), 34 deletions(-) diff --git a/MathGame/MathGame/Program.cs b/MathGame/MathGame/Program.cs index 1afeae48..61a7b402 100644 --- a/MathGame/MathGame/Program.cs +++ b/MathGame/MathGame/Program.cs @@ -45,34 +45,18 @@ switch (userInput) { case "1": - if (CheckStatusGame()) - { - break; - } SumOperation(); break; case "2": - if (CheckStatusGame()) - { - break; - } SubOperation(); break; case "3": - if (CheckStatusGame()) - { - break; - } DivOperation(); break; case "4": - if (CheckStatusGame()) - { - break; - } MultOperation(); break; @@ -119,33 +103,33 @@ int GetRandomNumber(int number) } -bool CheckStatusGame() +bool IsGameOver() { - if (questionsAsked == maxQuestionAsked) + if (questionsAsked != maxQuestionAsked) { - TimeSpan timeSpan = stopwatch.Elapsed; + return false; + } - string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", timeSpan.Hours, timeSpan.TotalMinutes, timeSpan.Seconds, timeSpan.Milliseconds / 10); + TimeSpan timeSpan = stopwatch.Elapsed; - gamesPlayed.Add($"You got {correctAnswers}/{maxQuestionAsked} correct answers! - Time: {elapsedTime}"); + string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", timeSpan.Hours, timeSpan.TotalMinutes, timeSpan.Seconds, timeSpan.Milliseconds / 10); - Console.WriteLine("\nGame over!\n"); - Console.WriteLine($"Here are your results: {correctAnswers}/{maxQuestionAsked}"); - Console.WriteLine($"You complete the game under: {elapsedTime}"); - Console.WriteLine("\nPress the Enter key to play a new game."); + gamesPlayed.Add($"You got {correctAnswers}/{maxQuestionAsked} correct answers! - Time: {elapsedTime}"); - correctAnswers = 0; - questionsAsked = 0; + Console.WriteLine("\nGame over!\n"); + Console.WriteLine($"Here are your results: {correctAnswers}/{maxQuestionAsked}"); + Console.WriteLine($"You complete the game under: {elapsedTime}"); + Console.WriteLine("\nPress the Enter key to play a new game."); - stopwatch.Reset(); - isChronometer = false; + correctAnswers = 0; + questionsAsked = 0; - Console.ReadLine(); + stopwatch.Reset(); + isChronometer = false; - return true; - } + Console.ReadLine(); - return false; + return true; } @@ -187,6 +171,9 @@ int DisplayOperation(char charOperation, int valueOne, int valueTwo) void SumOperation() { + if (IsGameOver()) + return; + numberOne = GetRandomNumber(difficulty); numberTwo = GetRandomNumber(difficulty); @@ -200,6 +187,9 @@ void SumOperation() void SubOperation() { + if (IsGameOver()) + return; + numberOne = GetRandomNumber(difficulty); numberTwo = GetRandomNumber(difficulty); @@ -213,6 +203,9 @@ void SubOperation() void DivOperation() { + if (IsGameOver()) + return; + numberOne = GetRandomNumber(difficulty); numberTwo = 2; @@ -241,6 +234,9 @@ void DivOperation() void MultOperation() { + if (IsGameOver()) + return; + numberOne = GetRandomNumber(difficulty); numberTwo = GetRandomNumber(difficulty); @@ -295,7 +291,7 @@ void PlayRandomGame() } Console.Clear(); - CheckStatusGame(); + IsGameOver(); } else From 89ffc73b93a8d05d93963b49fbe8a1b35e954b2a Mon Sep 17 00:00:00 2001 From: AlexRamos_ Date: Thu, 26 Mar 2026 22:39:14 -0600 Subject: [PATCH 4/5] Corrections - Update --- MathGame/MathGame/Program.cs | 178 +++++++++++++++++++++++++++-------- 1 file changed, 138 insertions(+), 40 deletions(-) diff --git a/MathGame/MathGame/Program.cs b/MathGame/MathGame/Program.cs index 61a7b402..40ca26aa 100644 --- a/MathGame/MathGame/Program.cs +++ b/MathGame/MathGame/Program.cs @@ -13,6 +13,7 @@ List gamesPlayed = []; bool isChronometer = false; +bool isRandom = false; int difficulty = 10; int userResult = 0; int numberOne = 0; @@ -36,8 +37,6 @@ DisplayDifficulty(); - CheckChronometerStatus(); - Console.WriteLine("Please type a number to choose an option from the menu: (exit)"); userInput = Console.ReadLine().Trim(); @@ -99,7 +98,7 @@ int GetRandomNumber(int number) { Random randomNumber = new(); - return randomNumber.Next(number); + return randomNumber.Next(1, number); } @@ -171,82 +170,178 @@ int DisplayOperation(char charOperation, int valueOne, int valueTwo) void SumOperation() { - if (IsGameOver()) + if (isRandom) + { + numberOne = GetRandomNumber(difficulty); + numberTwo = GetRandomNumber(difficulty); + + result = numberOne + numberTwo; + + userResult = DisplayOperation('+', numberOne, numberTwo); + + CheckQuestion(userResult, result); + return; + } - numberOne = GetRandomNumber(difficulty); - numberTwo = GetRandomNumber(difficulty); + CheckChronometerStatus(); - result = numberOne + numberTwo; + for (int i = 0; i < maxQuestionAsked; i++) + { + numberOne = GetRandomNumber(difficulty); + numberTwo = GetRandomNumber(difficulty); - userResult = DisplayOperation('+', numberOne, numberTwo); + result = numberOne + numberTwo; - CheckQuestion(userResult, result); + userResult = DisplayOperation('+', numberOne, numberTwo); + + CheckQuestion(userResult, result); + } + + Console.Clear(); + IsGameOver(); } void SubOperation() { - if (IsGameOver()) + if (isRandom) + { + numberOne = GetRandomNumber(difficulty); + numberTwo = GetRandomNumber(difficulty); + + result = Math.Abs(numberOne - numberTwo); + + userResult = DisplayOperation('-', numberOne, numberTwo); + + CheckQuestion(userResult, result); + return; + } - numberOne = GetRandomNumber(difficulty); - numberTwo = GetRandomNumber(difficulty); + CheckChronometerStatus(); - result = Math.Abs(numberOne - numberTwo); + for (int i = 0; i < maxQuestionAsked; i++) + { + numberOne = GetRandomNumber(difficulty); + numberTwo = GetRandomNumber(difficulty); - userResult = DisplayOperation('-', numberOne, numberTwo); + result = Math.Abs(numberOne - numberTwo); - CheckQuestion(userResult, result); + userResult = DisplayOperation('-', numberOne, numberTwo); + + CheckQuestion(userResult, result); + } + + Console.Clear(); + IsGameOver(); } void DivOperation() { - if (IsGameOver()) - return; + if (isRandom) + { + numberOne = GetRandomNumber(difficulty); + numberTwo = GetRandomNumber(difficulty); - numberOne = GetRandomNumber(difficulty); - numberTwo = 2; + result = numberOne % numberTwo; - result = numberOne % numberTwo; + if (result == 0) + { + result = numberOne / numberTwo; + } + else + { + while (result != 0) + { + numberOne = GetRandomNumber(difficulty); + numberTwo = GetRandomNumber(difficulty); - if (result == 0) - { - result = numberOne / numberTwo; + result = numberOne % numberTwo; + } + + result = numberOne / numberTwo; + } + + userResult = DisplayOperation('/', numberOne, numberTwo); + + CheckQuestion(userResult, result); + + return; } - else + + CheckChronometerStatus(); + + for (int i = 0; i < maxQuestionAsked; i++) { - while (result != 0) + numberOne = GetRandomNumber(difficulty); + numberTwo = GetRandomNumber(difficulty); + + result = numberOne % numberTwo; + + if (result == 0) { - numberOne = GetRandomNumber(difficulty); + result = numberOne / numberTwo; + } + else + { + while (result != 0) + { + numberOne = GetRandomNumber(difficulty); + numberTwo = GetRandomNumber(difficulty); + + result = numberOne % numberTwo; + } - result = numberOne % numberTwo; + result = numberOne / numberTwo; } - result = numberOne / numberTwo; - } + userResult = DisplayOperation('/', numberOne, numberTwo); - userResult = DisplayOperation('/', numberOne, numberTwo); + CheckQuestion(userResult, result); + } - CheckQuestion(userResult, result); + Console.Clear(); + IsGameOver(); } + void MultOperation() { - if (IsGameOver()) + if (isRandom) + { + numberOne = GetRandomNumber(difficulty); + numberTwo = GetRandomNumber(difficulty); + + result = numberOne * numberTwo; + + userResult = DisplayOperation('x', numberOne, numberTwo); + + CheckQuestion(userResult, result); + return; + } + + CheckChronometerStatus(); + + for (int i = 0; i < maxQuestionAsked; i++) + { + numberOne = GetRandomNumber(difficulty); + numberTwo = GetRandomNumber(difficulty); - numberOne = GetRandomNumber(difficulty); - numberTwo = GetRandomNumber(difficulty); + result = numberOne * numberTwo; - result = numberOne * numberTwo; + userResult = DisplayOperation('x', numberOne, numberTwo); - userResult = DisplayOperation('x', numberOne, numberTwo); + CheckQuestion(userResult, result); + } - CheckQuestion(userResult, result); + Console.Clear(); + IsGameOver(); } + void PlayRandomGame() { do @@ -258,8 +353,7 @@ void PlayRandomGame() if (userInput.Equals("y")) { - correctAnswers = 0; - questionsAsked = 0; + isRandom = true; CheckChronometerStatus(); @@ -291,8 +385,10 @@ void PlayRandomGame() } Console.Clear(); - IsGameOver(); + isRandom = false; + + IsGameOver(); } else { @@ -350,6 +446,7 @@ void ModifyDifficulty() while (userInput != "back"); } + void DisplayDifficulty() { switch (difficulty) @@ -368,6 +465,7 @@ void DisplayDifficulty() } } + void CheckChronometerStatus() { if (!isChronometer) From f5eb3a23bcd7995e69d6b98e9a260b9860ee1a4a Mon Sep 17 00:00:00 2001 From: AlexRamos_ Date: Thu, 26 Mar 2026 22:45:34 -0600 Subject: [PATCH 5/5] Fix - Update IsGameOver was change to void. --- MathGame/MathGame/Program.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/MathGame/MathGame/Program.cs b/MathGame/MathGame/Program.cs index 40ca26aa..9e5676d4 100644 --- a/MathGame/MathGame/Program.cs +++ b/MathGame/MathGame/Program.cs @@ -102,11 +102,11 @@ int GetRandomNumber(int number) } -bool IsGameOver() +void IsGameOver() { if (questionsAsked != maxQuestionAsked) { - return false; + return; } TimeSpan timeSpan = stopwatch.Elapsed; @@ -128,7 +128,7 @@ bool IsGameOver() Console.ReadLine(); - return true; + return; } @@ -447,7 +447,7 @@ void ModifyDifficulty() } -void DisplayDifficulty() +void DisplayDifficulty() { switch (difficulty) {