beeggi
beeggi

Reputation: 43

Trouble with do-while() ending

I'm having a little problem with this code below.

I marked the problem in the code also.

Its a simple craps game without the feature of balance or winning anything, it works fine, except it won't stop when nyStig == 7, in the long
if statement ,(if (stig == 4||stig == 5||stig == 6||stig == 8||stig == 9||stig == 10)), I know that I should just edit the ending of the do loop, (while(nyStig != stig || nyStig != 7)), but if I do that then nothing works.

//CRAPS

Random teningur1 = new Random ();
Random teningur2 = new Random ();

nyStig = ten3 + ten4;
ten3 = teningur1.Next(1,7);
ten4 = teningur2.Next(1,7);

ten1 = teningur1.Next(1,7);
ten2 = teningur2.Next(1,7);

stig = ten1 + ten2;

if (stig == 7 || stig == 11)
{
    //Print stuff to console
}

if (stig == 2 || stig == 3 || stig == 12)
{
    //Print stuff to console
}

if (stig == 4||stig == 5||stig == 6||stig == 8||stig == 9||stig == 10)
{
    do //the problem
    {
        Console.WriteLine ("Ýttu á enter til að kasta");
        Console.ReadLine();

        ten3 = teningur1.Next(1,7);
        ten4 = teningur1.Next(1,7);

        //Print stuff to console

        nyStig = ten3 + ten4;

        //Print stuff to console

        if (nyStig == stig)
        {
            //Print stuff to console
            Console.ReadKey();
        }
        else if (nyStig != 7)
        {
            Console.WriteLine ("Kemur .. kastaðu aftur ");
        }
        if (nyStig == 7)
        {
            //Print stuff to console
            Console.ReadKey();
        }
    }while(stig != nyStig); //if I add || nyStig != 7) it won't stop.

Upvotes: 0

Views: 92

Answers (1)

Bradley Thomas
Bradley Thomas

Reputation: 4097

The inner loop should be do while (dice-throw != 7 && dice-throw != point number)

Upvotes: 1

Related Questions