Yes... nephew...
Anyways to loop around for five games you need to put your input code inside the for loop, I've also got no idea what your doing with the string
numbers
and the statement
if (i < 4)
continue;
Isn't actually doing anything.
So to loop 5 times you should have a for loop like this:
for(int i=0; i<5; i++)
{
}
where
i
starts at zero (or start at 1 if you want but then you need to check for
i<6
or
i<=5
)
Also, instead of using a try-catch block you can use the function
bool Int32.TryParse(string str, out int val)
which will return true if it succeeds (and your result will be in
val
) and false if it fails.
So to check for valid input you'd need another kind of loop, the
do while
loop which will always run at least once and then keep going around until the statement at the end returns false.
bool validInput = false;
do
{
int score = 0;
validInput = Int32.TryParse(Console.ReadLine(), out score);
if(validInput)
{
if (score > 300)
{
Console.Writeline(...);
validInput = false;
}
etc.
}
}while(!validInput)
MSDN TryParse[
^]
Loops in C#[
^]
Your or your nephew may also want to pick up a beginners book for C# too, as it will cover all of the basics as well as best practices and provide examples; it would also server as a handy reference.