[Solved] C# method rollDice


EDIT:
Changed the while to a do-while, as this will always execute once, regardless of the initial value of a or b. It’s up to your preferences if you want to do it like this or with a while.

Next to that, I have changed the parameters of the while from while (a == 6 ; b ==6) to while(!(a == 6 && b ==6).

First of all, the ; in OP’s post is syntactically incorrect, and won’t work. It checks if a and/or b is 6 (depending on if the ; was supposed to be a || or a &&), and if it is, continues. That is the opposite of the desired effect, as OP wanted the loop to stop when both are 6.

while(!(a == 6 && b ==6) will check if both are 6, and if so it will stop the loop. If either is not 6, the loop will continue.

Try this:

int a;
int b;
//Do while because I'm assuming you always want to roll the dice at least once
    do 
    {
        a = rollDice();
        b = rollDice();
        Console.WriteLine("{0} {1}",a,b);
    } while (!(a == 6 && b == 6));

This will roll the dice until both are 6, as asked

3

solved C# method rollDice