mercredi 23 octobre 2019

I am trying to make a do while looping random number generator for D&D, but my code doesn't work

I figured I might try doing a do while loop for six separate random number generators to make six D&D attribute scores with a total score of 78 exactly. The program does not execute as intended, almost always showing a blank screen. Sometimes it does work, but its far too infrequent to be useful. Can this be reformatted in a different way to produce more consistent results?

Tried re-arranging the code, creating different static voids, but nothing seems to improve or help the problem.

        do
        {
            total = 78;

            strength = rng.Next(8, 19);
            strmod = (strength - 10) / 2;
            total = total - strength;

            dexterity = rng.Next(8, 19);
            dexmod = (dexterity - 10) / 2;
            total = total - dexterity;

            constitution = rng.Next(8, 19);
            conmod = (constitution - 10) / 2;
            total = total - constitution;

            intelligence = rng.Next(8, 19);
            intmod = (intelligence - 10) / 2;
            total = total - intelligence;

            wisdom = rng.Next(8, 19);
            wismod = (wisdom - 10) / 2;
            total = total - wisdom;

            charisma = rng.Next(8, 19);
            chamod = (charisma - 10) / 2;
            total = total - charisma;
        }
        while (total > 0 && total < 0);

        if (total == 0)
        {
            Console.WriteLine("These are your attribute scores and modifiers:");

this should run though each int, do the calculations, and come up with a total answer. The result of the total answer should determine whether to run through the code again with different random numbers, or move on to the if part.

most of the time, I just get a blank screen.




Aucun commentaire:

Enregistrer un commentaire