diff --git a/MathGame.Waaade105/MathGame.csproj b/MathGame.Waaade105/MathGame.csproj new file mode 100644 index 00000000..2150e379 --- /dev/null +++ b/MathGame.Waaade105/MathGame.csproj @@ -0,0 +1,10 @@ + + + + Exe + net8.0 + enable + enable + + + diff --git a/MathGame.Waaade105/MathGame.sln b/MathGame.Waaade105/MathGame.sln new file mode 100644 index 00000000..29acea9e --- /dev/null +++ b/MathGame.Waaade105/MathGame.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.8.34525.116 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MathGame", "MathGame.csproj", "{C25F02D2-4053-4142-88D7-F36A86E5604A}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {C25F02D2-4053-4142-88D7-F36A86E5604A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C25F02D2-4053-4142-88D7-F36A86E5604A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C25F02D2-4053-4142-88D7-F36A86E5604A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C25F02D2-4053-4142-88D7-F36A86E5604A}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {F70EC938-80DF-4B1D-8DCC-36C21276A214} + EndGlobalSection +EndGlobal diff --git a/MathGame.Waaade105/Program.cs b/MathGame.Waaade105/Program.cs new file mode 100644 index 00000000..c9fdc01b --- /dev/null +++ b/MathGame.Waaade105/Program.cs @@ -0,0 +1,143 @@ +Console.WriteLine( + "Welcome to the Math Game! Choose a math operation and answer 5 questions. " + + "You will receive 1 point for each correct answer."); + +List gamesHistory = []; +bool stillWantToPlay = true; + +while (stillWantToPlay) +{ + Console.WriteLine("What do you want to do?"); + Console.WriteLine("1.Addition\n2.Subtraction\n3.Multiplication\n4.Division\n5.Game history\n6.Exit"); + Console.WriteLine("Choice:"); + + int choice; + while (!int.TryParse(Console.ReadLine(), out choice)) + { + Console.WriteLine("Invalid choice."); + } + + switch (choice) + { + case 1: + PlayGame("+", gamesHistory); + break; + case 2: + PlayGame("-", gamesHistory); + break; + case 3: + PlayGame("*", gamesHistory); + break; + case 4: + PlayGame("/", gamesHistory); + break; + case 5: + ShowGameHistory(gamesHistory); + break; + case 6: + stillWantToPlay = false; + break; + + default: + Console.WriteLine("Invalid choice. Please select a number from 1 to 6."); + break; + } +} + +void ShowGameHistory(List gamesHistory) +{ + if(gamesHistory.Count == 0) + { + Console.WriteLine("No games have been played yet."); + return; + } + + foreach (string game in gamesHistory) + { + Console.WriteLine(game); + } +} + +void PlayGame(string operationSign, List gamesHistory) +{ + var random = new Random(); + int points = 0; + int askedQuestions = 5; + + for (int i = 1; i <= askedQuestions; i++) + { + int number1; + int number2; + + if (operationSign == "/") + { + do + { + number1 = random.Next(0, 101); + number2 = random.Next(1, 101); + } while (number1 % number2 != 0); + } + else + { + number1 = random.Next(0, 101); + number2 = random.Next(1, 101); + } + + + int result = 0; + switch (operationSign) + { + case "+": + result = number1 + number2; + break; + case "-": + result = number1 - number2; + break; + case "*": + result = number1 * number2; + break; + case "/": + result = number1 / number2; + break; + } + + Console.WriteLine($"question {i}:"); + Console.WriteLine($"{number1} {operationSign} {number2} = ?"); + + int answer; + while (!int.TryParse(Console.ReadLine(), out answer)) + { + Console.WriteLine("Please enter a valid number:"); + } + + if (result == answer) + { + Console.WriteLine("Correct! 1 point was added"); + points++; + } + else + { + Console.WriteLine("Not this time. The correct answer is " + result); + } + } + + string gameType = operationSign switch + { + "+" => "Addition", + "-" => "Subtraction", + "*" => "Multiplication", + "/" => "Division", + _ => "Unknown" + }; + + gamesHistory.Add($"{gameType} - Result: {points}/{askedQuestions}"); + + Console.WriteLine("You answered all questions."); + Console.WriteLine($"Result: {points}/{askedQuestions}"); +} + + + + + +