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
15 changes: 15 additions & 0 deletions .idea/.idea.CodeReviews.Console.MathGame.dir/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/.idea.CodeReviews.Console.MathGame.dir/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions MathGame.anemicmoth/MathGame2.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

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

</Project>
110 changes: 110 additions & 0 deletions MathGame.anemicmoth/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
// Difficulty based questions

string[,] beginnerQuestions = {{"1 + 5", "6"}, {"2 * 2", "4"}, {"21 + 3", "24"}};
string[,] moderateQuestions = {{"22/3", "7"}, {"17 * 2", "34"}, {"125 - 56", "69"}};
string[,] advancedQuestions = {{"147/6", "24"}, {"13 ^ 2", "169"}, {"23 * 25", "575"}};

string entry = "";


while (entry != "exit")
{
Console.WriteLine("Please enter a difficulty: b (beginner), m (moderate), a (advanced)");
entry = Console.ReadLine();
switch (entry)
{
case "b":
askQuestion(Difficulty.Beginner);
break;
case "m":
askQuestion(Difficulty.Moderate);
break;
case "a":
askQuestion(Difficulty.Advanced);
break;
default:
Console.WriteLine("Invalid input.");
break;
}
Console.WriteLine("Do you want to play again? Press Enter to continue or type \"exit\" to quit.");
entry = Console.ReadLine();
}

void askQuestion(Difficulty difficulty)
{
System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch();
Tuple<string, string> question = createQuestion(difficulty);

timer.Start();
Console.WriteLine(question.Item1);
entry = Console.ReadLine();
timer.Stop();

TimeSpan ts = timer.Elapsed;
string elapsedTime = String.Format("{0:00}:{1:00}", ts.Minutes, ts.Seconds);
if (entry != null && entry.Equals(question.Item2))
{
Console.WriteLine($"Correct! Your time to answer is: {elapsedTime} min");
}
else
{
Console.WriteLine($"That was the wrong answer. The correct answer is: {question.Item2}");
}
}

Tuple<String, String> createQuestion(Difficulty difficulty)
{
Random rand = new Random();
int num1 = rand.Next(1, 51);
int num2 = rand.Next(1, 51);
int operand = 0;
int result;

switch (difficulty)
{
case Difficulty.Beginner:
operand = rand.Next(0, 2);
break;
case Difficulty.Moderate:
operand = rand.Next(0, 4);
break;
case Difficulty.Advanced:
num1 = rand.Next(51, 201);
num2 = rand.Next(51, 201);
operand = rand.Next(2, 5);
if (operand == 4)
{
num1 = rand.Next(1, 51);
num2 = rand.Next(1, 5);
}
break;
}

switch (operand)
{
case 0:
result = num1 + num2;
return new Tuple<string, string>(num1 + " + " + num2, Convert.ToString(result));
case 1:
result = num1 - num2;
return new Tuple<string, string>(num1 + " - " + num2, Convert.ToString(result));
case 2:
result = num1 * num2;
return new Tuple<string, string>(num1 + " * " + num2, Convert.ToString(result));
case 3:
result = num1 / num2;
return new Tuple<string, string>(num1 + " / " + num2, Convert.ToString(result));
case 4:
result = Convert.ToInt32(Math.Pow(num1, num2));
return new Tuple<string, string>(num1 + " ^ " + num2, Convert.ToString(result));
}

return null;
}

enum Difficulty
{
Beginner,
Moderate,
Advanced
}