diff --git a/Emne 3/Krokodillespillet/Krokodillespillet.sln b/Emne 3/Krokodillespillet/Krokodillespillet.sln new file mode 100644 index 0000000..19b26f1 --- /dev/null +++ b/Emne 3/Krokodillespillet/Krokodillespillet.sln @@ -0,0 +1,16 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Krokodillespillet", "Krokodillespillet\Krokodillespillet.csproj", "{7A64F3FF-CB86-427B-A77E-320415991537}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {7A64F3FF-CB86-427B-A77E-320415991537}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7A64F3FF-CB86-427B-A77E-320415991537}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7A64F3FF-CB86-427B-A77E-320415991537}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7A64F3FF-CB86-427B-A77E-320415991537}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/Emne 3/Krokodillespillet/Krokodillespillet/Krokodillespillet.csproj b/Emne 3/Krokodillespillet/Krokodillespillet/Krokodillespillet.csproj new file mode 100644 index 0000000..2f4fc77 --- /dev/null +++ b/Emne 3/Krokodillespillet/Krokodillespillet/Krokodillespillet.csproj @@ -0,0 +1,10 @@ + + + + Exe + net8.0 + enable + enable + + + diff --git a/Emne 3/Krokodillespillet/Krokodillespillet/Program.cs b/Emne 3/Krokodillespillet/Krokodillespillet/Program.cs new file mode 100644 index 0000000..5e09fd9 --- /dev/null +++ b/Emne 3/Krokodillespillet/Krokodillespillet/Program.cs @@ -0,0 +1,84 @@ +using System; + +namespace KrokodilleSpillet +{ + class Program + { + static bool running = true; + static string rightAnswer; + static void Main(string[] args) + { + ProgramLoop(); + } + + static void ProgramLoop() + { + + while (running == true) + { + var rand1 = new Random(); + var rand2 = new Random(); + int randomNumber = rand1.Next(0,11); + int randomNumer2 = rand2.Next(0,11); + + Console.WriteLine("Skriv inn riktig > < eller =. Alle andre tegn avslutter programmet"); + Console.WriteLine($"Hva er riktig tegn i utrykket {randomNumber}_{randomNumer2}"); + string answer = Console.ReadLine(); + GetRightAnswer(randomNumber, randomNumer2); + CheckAnswer(answer); + } + } + static string GetRightAnswer(int rand1, int rand2) + { + if (rand1 == rand2) + { + rightAnswer = "="; + } else if (rand1 > rand2) + { + rightAnswer = ">"; + } else if (rand1 < rand2) + { + rightAnswer = "<"; + } + return rightAnswer; + } + + static void CheckAnswer(string answer) + { + if (answer != "<" && answer != ">" && answer != "=") + { + Console.WriteLine("På gjensyn :-)"); + running = false; + } + else if (answer == rightAnswer) + { + PrintResponse(true); + Console.Clear(); + + } else if(answer != rightAnswer) + { + PrintResponse(false); + Console.Clear(); + } + + } + + static void PrintResponse(bool arg) + { + if (arg == true) + { + Console.WriteLine($"\nDet er riktig"); + Console.WriteLine($"\nTrykk en tast for å prøve igjen"); + Console.ReadKey(); + } + else + { + Console.WriteLine($"\nDet er feil"); + Console.WriteLine($"\nRiktig svar var {rightAnswer}"); + Console.WriteLine($"\nTrykk en tast for å prøve igjen"); + Console.ReadKey(); + } + } + } +} +