From 533468c4015040e9f3454184a9c7ca931955b27f Mon Sep 17 00:00:00 2001 From: awerner9 Date: Wed, 20 May 2026 20:01:29 -0600 Subject: [PATCH 1/2] create addition game and menu --- MathGame/MathGame.csproj | 10 ++++ MathGame/Program.cs | 106 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 116 insertions(+) create mode 100644 MathGame/MathGame.csproj create mode 100644 MathGame/Program.cs diff --git a/MathGame/MathGame.csproj b/MathGame/MathGame.csproj new file mode 100644 index 00000000..ed9781c2 --- /dev/null +++ b/MathGame/MathGame.csproj @@ -0,0 +1,10 @@ + + + + Exe + net10.0 + enable + enable + + + diff --git a/MathGame/Program.cs b/MathGame/Program.cs new file mode 100644 index 00000000..33bb232d --- /dev/null +++ b/MathGame/Program.cs @@ -0,0 +1,106 @@ +// You need to create a game that consists of asking the player what's the result of a math question (i.e. 9 x 9 = ?), +// collecting the input and adding a point in case of a correct answer. +// A game needs to have at least 5 questions. +// The divisions should result on INTEGERS ONLY and dividends should go from 0 to 100. +// Example: Your app shouldn't present the division 7/2 to the user, since it doesn't result in an integer. +// Users should be presented with a menu to choose an operation +// You should record previous games in a List and there should be an option in the menu for the user to visualize a history of previous games. +// You don't need to record results on a database. Once the program is closed the results will be deleted. + +// :: gives user a clean menu to choose from for selecting a type of game + +// TODO +// add multiplication game +// add subtraction game +// add division game (make sure dividends are divisible) +// add continuity (back to menu after game) +// figure out how to record games in list and add menu option to view previous games + +static void Menu() +{ + string? userInput = ""; + + do + { + Console.WriteLine("What operation would you like to use? (choose a number)"); + Console.WriteLine("1: Addition"); + Console.WriteLine("2: Subtraction"); + Console.WriteLine("3: Multiplication"); + Console.WriteLine("4: Division"); + userInput = Console.ReadLine(); + } while (userInput != "1" && userInput != "2" && userInput != "3" && userInput != "4"); + + if (userInput == "1") + { + AdditionGame(); + } + else if (userInput == "2") + { + SubtractionGame(); + } + else if (userInput == "3") + { + MultiplicationGame(); + } + else if (userInput == "4") + { + DivisionGame(); + } +} + +Menu(); + +// :: generates 5 addition questions + +static int generateNumber() +{ + Random rnd = new Random(); + int randomNumber = rnd.Next(1, 11); + + return randomNumber; +} + +static void AdditionGame() +{ + Console.Clear(); + + int correctAnswer = 0; + + for (int i = 1; i <= 5; i++) + { + int numOne = generateNumber(); + int numTwo = generateNumber(); + + Console.WriteLine($"{i}. What is {numOne} + {numTwo}?"); + int? answer = int.Parse(Console.ReadLine()!); + if (answer == (numOne + numTwo)) + { + ++correctAnswer; + Console.WriteLine("Correct!"); + } + else + { + Console.WriteLine("Incorrect!"); + } + } + + Console.WriteLine($"You got {correctAnswer} out of 5 correct."); +} + +static void SubtractionGame() +{ + int numOne = generateNumber(); + int numTwo = generateNumber(); +} + +static void MultiplicationGame() +{ + int numOne = generateNumber(); + int numTwo = generateNumber(); +} + +static void DivisionGame() +{ + int numOne = generateNumber(); + int numTwo = generateNumber(); +} \ No newline at end of file From 9e14087d51d4a8bed81fc9fa5eab240dc54dc1ae Mon Sep 17 00:00:00 2001 From: awerner9 Date: Wed, 20 May 2026 20:46:53 -0600 Subject: [PATCH 2/2] finish math game --- MathGame/Program.cs | 154 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 126 insertions(+), 28 deletions(-) diff --git a/MathGame/Program.cs b/MathGame/Program.cs index 33bb232d..88806b02 100644 --- a/MathGame/Program.cs +++ b/MathGame/Program.cs @@ -10,57 +10,70 @@ // :: gives user a clean menu to choose from for selecting a type of game // TODO -// add multiplication game -// add subtraction game // add division game (make sure dividends are divisible) -// add continuity (back to menu after game) // figure out how to record games in list and add menu option to view previous games -static void Menu() +List results = new List(); + +static void Menu(List results) { string? userInput = ""; do { Console.WriteLine("What operation would you like to use? (choose a number)"); - Console.WriteLine("1: Addition"); - Console.WriteLine("2: Subtraction"); - Console.WriteLine("3: Multiplication"); - Console.WriteLine("4: Division"); + Console.WriteLine("1. Addition"); + Console.WriteLine("2. Subtraction"); + Console.WriteLine("3. Multiplication"); + Console.WriteLine("4. Division"); + Console.WriteLine("5. View Previous Games"); userInput = Console.ReadLine(); - } while (userInput != "1" && userInput != "2" && userInput != "3" && userInput != "4"); + } while (userInput != "1" && userInput != "2" && userInput != "3" && userInput != "4" && userInput != "5"); if (userInput == "1") { - AdditionGame(); + AdditionGame(results); } else if (userInput == "2") { - SubtractionGame(); + SubtractionGame(results); } else if (userInput == "3") { - MultiplicationGame(); + MultiplicationGame(results); } else if (userInput == "4") { - DivisionGame(); + DivisionGame(results); + } + else if (userInput == "5") + { + ViewGames(results); } } -Menu(); - -// :: generates 5 addition questions +Menu(results); static int generateNumber() { Random rnd = new Random(); - int randomNumber = rnd.Next(1, 11); + int randomNumber = rnd.Next(1, 101); return randomNumber; } -static void AdditionGame() +static void ViewGames(List results) +{ + foreach(string result in results) + { + Console.WriteLine(result); + } + Console.WriteLine("Press enter to return to the menu"); + Console.ReadLine(); + Menu(results); +} + +static void AdditionGame(List results) { Console.Clear(); @@ -84,23 +97,108 @@ static void AdditionGame() } } - Console.WriteLine($"You got {correctAnswer} out of 5 correct."); + Console.WriteLine($"\nYou got {correctAnswer} out of 5 correct.\n"); + Console.WriteLine("Press enter to return to the menu"); + Console.ReadLine(); + results.Add($"Addition Game Result: {correctAnswer}/5"); + Menu(results); } -static void SubtractionGame() +static void SubtractionGame(List results) { - int numOne = generateNumber(); - int numTwo = generateNumber(); + Console.Clear(); + + int correctAnswer = 0; + + for (int i = 1; i <= 5; i++) + { + int numOne = generateNumber(); + int numTwo = generateNumber(); + + Console.WriteLine($"{i}. What is {numOne} - {numTwo}?"); + int? answer = int.Parse(Console.ReadLine()!); + if (answer == (numOne - numTwo)) + { + ++correctAnswer; + Console.WriteLine("Correct!"); + } + else + { + Console.WriteLine("Incorrect!"); + } + } + + Console.WriteLine($"\nYou got {correctAnswer} out of 5 correct.\n"); + Console.WriteLine("Press enter to return to the menu"); + Console.ReadLine(); + results.Add($"Subtraction Game Result: {correctAnswer}/5"); + Menu(results); } -static void MultiplicationGame() +static void MultiplicationGame(List results) { - int numOne = generateNumber(); - int numTwo = generateNumber(); + Console.Clear(); + + int correctAnswer = 0; + + for (int i = 1; i <= 5; i++) + { + int numOne = generateNumber(); + int numTwo = generateNumber(); + + Console.WriteLine($"{i}. What is {numOne} * {numTwo}?"); + int? answer = int.Parse(Console.ReadLine()!); + if (answer == (numOne * numTwo)) + { + ++correctAnswer; + Console.WriteLine("Correct!"); + } + else + { + Console.WriteLine("Incorrect!"); + } + } + + Console.WriteLine($"\nYou got {correctAnswer} out of 5 correct.\n"); + Console.WriteLine("Press enter to return to the menu"); + Console.ReadLine(); + results.Add($"Multiplication Game Result: {correctAnswer}/5"); + Menu(results); } -static void DivisionGame() +static void DivisionGame(List results) { - int numOne = generateNumber(); - int numTwo = generateNumber(); + Console.Clear(); + + int correctAnswer = 0; + + for (int i = 1; i <= 5; i++) + { + int numOne = 0; + int numTwo = 1; + do + { + Random rnd = new Random(); + numOne = generateNumber(); + numTwo = generateNumber(); + } while(numOne % numTwo != 0); + + Console.WriteLine($"{i}. What is {numOne} / {numTwo}?"); + int? answer = int.Parse(Console.ReadLine()!); + if (answer == (numOne / numTwo)) + { + ++correctAnswer; + Console.WriteLine("Correct!"); + } + else + { + Console.WriteLine("Incorrect!"); + } + } + + Console.WriteLine($"\nYou got {correctAnswer} out of 5 correct.\n"); + Console.WriteLine("Press enter to return to the menu"); + Console.ReadLine(); + results.Add($"Division Game Result: {correctAnswer}/5"); + Menu(results); } \ No newline at end of file