Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions MathProject/MathProject.slnx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<Solution>
<Project Path="MathProject/MathProject.csproj" />
</Solution>
14 changes: 14 additions & 0 deletions MathProject/MathProject/MathProject.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Spectre.Console" Version="0.57.1" />
</ItemGroup>

</Project>
82 changes: 82 additions & 0 deletions MathProject/MathProject/Program.cs
Original file line number Diff line number Diff line change
@@ -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<int, int>();

while(true)
{
var choice = AnsiConsole.Prompt(new SelectionPrompt<string>().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;

}


}

}
1 change: 1 addition & 0 deletions MathProject/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A Console Based Math Game developed in C#