Before you flag this, I've tried several solutions found here (I swear it is not duplicate) and end up with errors causing VS to crash.
EDIT: Some people said my loop doesn't work. The issue is not there, it has to do with the keypress
Here is my original code :
while (true)
{
Console.WriteLine("Voer een getal in : ");
string invoer = Console.ReadLine();
Console.Write("Voer de macht in waarmee u wilt vermenigvuldigen :");
string macht = Console.ReadLine();
int getal = Convert.ToInt32(invoer);
int getalmacht = Convert.ToInt32(macht);
int uitkomst = (int)Math.Pow(getal, getalmacht);
Console.WriteLine("De macht van " + getal + " is " + uitkomst + " .");
Console.ReadLine();
}
It worked fine but it did not look for keypresses.
Here is one that checks for keypress and does not throw a error :
namespace Democonsole
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Press ESC to stop.");
do
{
while (!Console.KeyAvailable)
{
Console.WriteLine("Voer een getal in : ");
string invoer = Console.ReadLine();
Console.Write("Voer de macht in waarmee u wilt vermenigvuldigen :");
string macht = Console.ReadLine();
int getal = Convert.ToInt32(invoer);
int getalmacht = Convert.ToInt32(macht);
int uitkomst = (int)Math.Pow(getal, getalmacht);
Console.WriteLine("De macht van " + getal + " is " + uitkomst + " .");
Console.ReadLine();
}
} while (Console.ReadKey(true).Key != ConsoleKey.Escape);
}
}
}
It does however upon running crash and give the error as seen in the printscreen.
Any other way to do this?
EDIT : Added more examples of solutions I tried due to request.
static void Main(string[] args)
{
var myWorker = new MyWorker();
myWorker.DoStuff();
Console.WriteLine("Press any key to stop...");
Console.ReadKey();
}
break
while (true)
{
Console.WriteLine("Voer een getal in : ");
string invoer = Console.ReadLine();
Console.Write("Voer de macht in waarmee u wilt vermenigvuldigen :");
string macht = Console.ReadLine();
int getal = Convert.ToInt32(invoer);
int getalmacht = Convert.ToInt32(macht);
int uitkomst = (int)Math.Pow(getal, getalmacht);
Console.WriteLine("De macht van " + getal + " is " + uitkomst + " .");
Console.ReadLine();
Console.Keypress()
`