So, I am refreshing myself on C#. I decided to write a simple calculator program and was showing my daughter. I added a while loop to my main and added an if statement to break the loop if the user doesn't want to repeat the process...I added some methods for the operators and added some info at the end. After that it stopped repeating and just totally skips getting input from the "x = (char)Console.Read();" line and exits. Helpful advice would be appreciated, I am still a beginner with coding so please don't criticize me, thanks. Full code below:
using System;
namespace TrueCalculator
{
class Program
{
public static int addition(int num1, int num2)
{
int result = num1 + num2;
return result;
}
public static int subtraction(int num1, int num2)
{
int result = num1 - num2;
return result;
}
public static int division(int num1, int num2)
{
int result = num1 / num2;
return result;
}
public static int multiplication(int num1, int num2)
{
int result = num1 * num2;
return result;
}
static void Main(string[] args)
{
char x = 'y';
while (x == 'y' || x == 'Y')
{
Console.WriteLine("\t\t\tTrue Calculator\n\t\t Only uses whole numbers!\n\t\t ***BETA VERSION***");
Console.WriteLine("Enter first number: ");
int num1 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter second number: ");
int num2 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Please type desired operator to perform: +, -, /, *");
char op = (char)Console.Read();
if (op == '+')
{
Console.WriteLine(num1 + " + " + num2 + " = " + addition(num1, num2));
}
else if (op == '-')
{
Console.WriteLine(num1 + " - " + num2 + " = " + subtraction(num1, num2));
}
else if (op == '/')
{
Console.WriteLine(num1 + " / " + num2 + " = " + division(num1, num2));
}
else if (op == '*')
{
Console.WriteLine(num1 + " * " + num2 + " = " + multiplication(num1, num2));
}
Console.WriteLine("Reset, y/n?");
x = Convert.ToChar(Console.Read());
if (x == 'n' || x == 'N')
{
break;
}
}
Console.WriteLine("\n\n\t\t\tThank you for using True Calculator\n\nDeveloped by Duster_2015..." +
"\nAny comments or suggestions send to: " +
"FIXME: Enter your Duster email.");
Console.ReadKey();
}
}
}