I'm trying to convert the string n
to an int
called numar
. I can run the program, but after I exit the console, it gives me this error:
"System.FormatException: 'Input string was not in a correct format.
It throws on the line containing int numar = Convert.ToInt32(n);
. How would I fix this?
static void Main(string[] args)
{
int res = 1;
string n = "";
while (n != "x")
{
n = Console.ReadLine();
int numar = Convert.ToInt32(n);
res = res * numar;
}
Console.WriteLine(res);
}