dimanche 13 mai 2018

My simulation doesn't doesn't run or loop

I have to answer the following question:

In the land of Puzzlevania, Aaron, Bob, and Charlie had an argument over which one of them was the greatest puzzler of all time. To end the argument once and for all, they agreed on a duel to the death. Aaron is a poor shooter and only hits his target with a probability of 1/3. Bob is a bit better and hits his target with a probability of 1/2. Charlie is an expert marksman and never misses. A hit means a kill and the person hit drops out of the duel. To compensate for the inequities in their marksmanship skills, it is decided that the contestants would fire in turns starting with Aaron, followed by Bob, and then by Charlie. The cycle would repeat until there was one man standing. And that man would be remembered as the greatest puzzler of all time.

I currently have the following code wrote:

int puzzle_count = 0;                                   
double aaron_accuracy = 1.0 / 3.0;
double bob_accuracy = 1.0 / 2.0;
double charlie_accuracy = 1.0;
bool aaron_alive;
bool bob_alive;
bool charlie_alive;
double random;
double aaronwins = 0;
double bobwins = 0;
double charliewins = 0;
double aaron_percent = 0;
double bob_percent = 0;
double charlie_percent = 0;

printf("\n Who is the greatest puzzler of all time?");
while (puzzle_count < 10000) {
    aaron_alive = true;
    bob_alive = true;
    charlie_alive = true;
    while (((aaron_alive = true) && (bob_alive = true)) || 
        ((bob_alive = true) && (charlie_alive = true)) || 
        ((aaron_alive = true) && (charlie_alive = true))) {

        if (aaron_alive = true) {
            if (charlie_alive = true) {
                random = rand() % 100;
                if (random < aaron_accuracy * 100) {
                    charlie_alive = false;
                        if (random > aaron_accuracy * 100) {
                            charlie_alive = true;
                        }
                }
            }
            if (charlie_alive = false) {
                random = rand() % 100;
                if (random < aaron_accuracy * 100) {
                    bob_alive = false;
                        if (random > aaron_accuracy * 100) {
                            bob_alive = true;
                        }
                }
            }
        }
        if (bob_alive = true) {
            if (charlie_alive = true) {
                random = rand() % 100;
                if (random < bob_accuracy * 100) {
                    charlie_alive = false;
                        if (random > bob_accuracy * 100) {
                            charlie_alive = true;
                        }
                }
            }
            if (charlie_alive = false) {
                random = rand() % 100;
                if (random < bob_accuracy * 100) {
                    aaron_alive = false;
                        if (random > bob_accuracy * 100) {
                            aaron_alive = true;
                        }
                }
            }
        }
        if (charlie_alive = true) {
            if (bob_alive = true) {
                random = rand() % 100;
                if (random < charlie_accuracy * 100) {
                    bob_alive = false;
                        if (random > charlie_accuracy * 100) {
                            bob_alive = true;
                        }
                }
            }
            if (bob_alive = false) {
                random = rand() % 100;
                if (random < charlie_accuracy * 100) {
                    aaron_alive = false;
                        if (random > charlie_accuracy * 100) {
                            aaron_alive = true;
                        }
                }
            }
        }


        if (aaron_alive = true)
            aaronwins++;
        if (bob_alive = true)
            bobwins++;
        if (charlie_alive = true)
            charliewins++;

    }
    puzzle_count++;
}

if (aaronwins + bobwins + charliewins == 10000) {
    aaron_percent = aaronwins / 10000;
    bob_percent = bobwins / 10000;
    charlie_percent = charliewins / 10000;

    printf("\n  Aaron won %f/10000 or %.2f% of the time", aaronwins, aaron_percent);
    printf("\n  Bob won %f/10000 or %.2f% of the time", bobwins, bob_percent);
    printf("\n  Charlie won %f/10000 or %.2f% of the time", charliewins, charlie_percent);
}
return 0;

}

When I run the code it returns no errors or warnings and opens up but doesn't run the simulation. I have read the code multiple times and couldn't seem to find any cause for this issue.

I apologize in advance if this is because of a typographical error. This is the first programming course I am taking and my code writing and troubleshooting skills aren't the greatest.

TIA




Aucun commentaire:

Enregistrer un commentaire