From 4403d1da3e1813baf140698dabe372b9e6455087 Mon Sep 17 00:00:00 2001 From: sange Date: Sun, 28 Jun 2026 16:50:10 +0530 Subject: [PATCH] Add MathProject files --- MathProject/MathProject.slnx | 3 + MathProject/MathProject/MathProject.csproj | 14 ++++ MathProject/MathProject/Program.cs | 82 ++++++++++++++++++++++ MathProject/README.md | 1 + 4 files changed, 100 insertions(+) create mode 100644 MathProject/MathProject.slnx create mode 100644 MathProject/MathProject/MathProject.csproj create mode 100644 MathProject/MathProject/Program.cs create mode 100644 MathProject/README.md diff --git a/MathProject/MathProject.slnx b/MathProject/MathProject.slnx new file mode 100644 index 00000000..7289f685 --- /dev/null +++ b/MathProject/MathProject.slnx @@ -0,0 +1,3 @@ + + + diff --git a/MathProject/MathProject/MathProject.csproj b/MathProject/MathProject/MathProject.csproj new file mode 100644 index 00000000..85c10f3f --- /dev/null +++ b/MathProject/MathProject/MathProject.csproj @@ -0,0 +1,14 @@ + + + + Exe + net10.0 + enable + enable + + + + + + + diff --git a/MathProject/MathProject/Program.cs b/MathProject/MathProject/Program.cs new file mode 100644 index 00000000..ef53da1f --- /dev/null +++ b/MathProject/MathProject/Program.cs @@ -0,0 +1,82 @@ + + +using Spectre.Console; +using System.Diagnostics; + +namespace MathProject +{ + class Program + { + + public static void Main(string[] args) + { + int count = 1; + var history = new Dictionary(); + + while(true) + { + var choice = AnsiConsole.Prompt(new SelectionPrompt().Title("* * MENU * * ").AddChoices("Quiz me ..", "Previous Scores", "Exit")); + int points = 0; + switch (choice) + { + + case "Quiz me ..": + var timer = new Stopwatch(); + timer.Start(); + Console.WriteLine(" what is 5 + 5"); + int result1 = Convert.ToInt32(Console.ReadLine()); + points = MathOperation("add", result1, points); + + Console.WriteLine("What is 10 - 2"); + int result2 = Convert.ToInt32(Console.ReadLine()); + points = MathOperation("sub", result2, points); + + Console.WriteLine("what is 9 * 5"); + int result3 = Convert.ToInt32(Console.ReadLine()); + points = MathOperation("mul", result3, points); + Console.WriteLine("What is 10 / 10"); + int result4 = Convert.ToInt32(Console.ReadLine()); + points = MathOperation("div", result4, points); + timer.Stop(); + TimeSpan timeTaken = timer.Elapsed; + Console.WriteLine($"Time taken: {timeTaken}"); + history.Add(count, points); + count++; + break; + case "Previous Scores": + for(int i = 1; i <= history.Count; i++) + { + Console.WriteLine($"Attempt {i} : points {history[i]} "); + } + break; + case "Exit": + Environment.Exit(0); + break; + default: + Console.WriteLine("Invalid choice"); + break; + + } + + + } + } + + static int MathOperation(string operation, int result, int points) + { + if(operation == "add" && result == 10 || operation == "sub" && result == 8 || operation == "div" && result == 1 || operation == "mul" && result == 45) + { + Console.WriteLine("Correct answer"); + points += 10; + } + + Console.WriteLine("Wrong answer"); + + return points; + + } + + + } + +} \ No newline at end of file diff --git a/MathProject/README.md b/MathProject/README.md new file mode 100644 index 00000000..5047a123 --- /dev/null +++ b/MathProject/README.md @@ -0,0 +1 @@ +A Console Based Math Game developed in C#