I'm trying to write a program to keep track of how many times I die in a game. The program runs, accepts user input, and keeps track of the information. When I run the program, it works, but you can only enter one key. For example, if you start it up and then press "D," it will add one to the "deaths" variable, but then you won't be able to type in anything else. Here's the code:
Console.WriteLine(
"To add one to Deaths stat, press D. To add one to Charms Stat, press C. " +
"To see all stats, press S.");
int deaths = 0;
int charms = 23;
ConsoleKeyInfo datKey;
datKey = Console.ReadKey();
if (datKey.Key == ConsoleKey.D)
{
deaths = deaths + 1;
Console.WriteLine();
Console.WriteLine("Death Added");
}
if (datKey.Key == ConsoleKey.C)
{
charms = charms + 1;
Console.WriteLine();
Console.WriteLine("Charm Added");
}
if (datKey.Key == ConsoleKey.S)
{
Console.WriteLine();
Console.WriteLine($"You have {charms} charms \nYou have died {deaths} times");
while, for, do while. Oh and don't even start usingGOTO, that only leads to confusing errors.