Console.WriteLine (\"Please enter some numbers\");
int sum = 0;
for(;;)
{
string input = Console.ReadLine ();
if
I would rewrite this entirely (Your original error was because you were trying to add a string
to an int
, and not the parsed input as an int
)
Console.WriteLine ("Please enter some numbers");
int sum = 0;
while (true)
{
int parsedInput = 0;
string input = Console.ReadLine();
if (!string.IsNullOrEmpty(input) && int.TryParse(input, out parsedInput))
{
sum += parsedInput;
Console.WriteLine (sum);
}
else
break;
}