+ 2

Creating a "die roll" program

I have a problem with my code, I want to roll two dies until both get 6, but I can only make to stop the dies when one get 6 and not both. I know that the problem is in the "while" condition, but I don't know how to change it to work, please help. Here's the code: Console.WriteLine("Roll the dies until you get two sixes"); Random numberGen = new Random(); int rollone = 0; int rolltwo = 1; int attempts = 2; while(()rollone != 6) && (rolltwo != 6)) { rollone = numberGen.Next(1, 7); rolltwo = numberGen.Next(1, 7); Console.WriteLine("\n You rolled: " + rollone + " and " + rolltwo); attempts++; } Console.WriteLine("\nIt took you " + attempts + " attempts to get two sixes");

5th Mar 2022, 8:22 PM
Wiki
2 Answers
+ 2
while(rollone!=6 || rolltwo !=6) // logic or checks both not= before proceeding while(!(rollone==6 && rolltwo==6)) // logic and needs both to be true, then flips to not
5th Mar 2022, 9:17 PM
HungryTradie
HungryTradie - avatar
+ 2
Thanks for the answers, they help me a lot to learn.
5th Mar 2022, 9:28 PM
Wiki