{
Random r = new Random();
int current = 0;
int noa = 0;
while (current != 6) {
current =r.Next(1,7);
noa += 1;
Console.WriteLine(current + " has been rolled.");
}
if (noa >= 10)
{
Console.WriteLine("You were unlucky and it took you "+ noa + " times to roll a 6!");
}
if (noa <= 5)
{
Console.WriteLine("You were quite lucky and it took you " + noa + " times to roll a 6!");
}
else
{
Console.WriteLine("It took you " + noa + " times to roll a 6!");
}
Console.ReadKey();
}
}
} So problem occurs when noa(number of attempts) is higher than 10 and what it shows is:
2 has been rolled.
5 has been rolled.
4 has been rolled.
5 has been rolled.
5 has been rolled.
1 has been rolled.
2 has been rolled.
1 has been rolled.
3 has been rolled.
4 has been rolled.
6 has been rolled.
You were unlucky and it took you 11times to roll a 6!
It took you 11 times to roll a 6!
And what I dont want to happen is console writing that second line "It took you 11 times to roll a 6!". Why is this happening? Thank you in advance.
Aucun commentaire:
Enregistrer un commentaire