0
I wonder if we can make this code not stop when I type a letter instead of a number, just correcting and telling to type a number.
namespace calculadora
{
class Program {
static void Main() {
ConsoleKey bta = ConsoleKey.A;
while (bta == ConsoleKey.Escape == false) {
double n1, n2;
Console.Clear();
n1 = double.Parse(Console.ReadLine());
ConsoleKey mais = Console.ReadKey().Key;
if (mais == ConsoleKey.Add) {
Console.WriteLine(" ");
string b = Console.ReadLine();
n2 = double.Parse(b);
Console.WriteLine("{0} + {1} = {2}", n1, n2, n1 + n2);
}
if (mais == ConsoleKey.Subtract) {
Console.WriteLine(" ");
string b = Console.ReadLine();
n2 = double.Parse(b);
Console.WriteLine("{0} - {1} = {2}", n1, n2, n1 - n2);
}
if (mais == ConsoleKey.Multiply) {
Console.WriteLine(" ");
string b = Console.ReadLine();
n2 = double.Parse(b);
Console.WriteLine("{0} . {1} = {2}", n1, n2, n1 * n2);
}
if (mais == ConsoleKey.Divide) {
Console.WriteLine(" ");
string b = Console.ReadLine();
n2 = double.Parse(b);
double Res = n1 / n2;
Console.WriteLine("{0} / {1} = {2}", n1, n2, Res);
}
Console.WriteLine(" ");
bta = Console.ReadKey().Key;
}
}
}
}
Do not use greetings or greetings, see what kind of behavior is expected from users? and how to create a [Mre] to prepare a question GOOD and CLEAR
– gleisin-dev