Why do the rules for my game print when I tell them not to?
My code uses the following function:
Here is the section of my main that calls the function:
// function: prn_rules
// pre: none
// post: prints the rules
"The goal is to be the first player to reach 100 points.\n\n"
"On a turn, a player rolls the two dice repeatedly until either a 1 is rolled \n"
"or the player chooses to hold and stop rolling.\n\n"
"If a 1 is rolled, that player's turn ends and no points are earned for the round.\n"
"If the player chooses to hold, all of the points rolled during that round are added to their score.\n\n"
"If a player rolls double 1s, that counts as 25 points.\n"
"Other doubles are worth 2x double points, so that a 2-2 is worth 8 points; 3-3 is worth 12; \n"
"4-4 is worth 16; 5-5 is worth 20; and 6-6 is worth 24.\n\n"
"When a player reaches a total of 100 or more points, the game ends and that player is the winner.\n");
That isn't the complete main, but just the first part that calls prnRules. The problem is, if I answer "n" to wanting to view the rules, it still prints them every time. What am I doing wrong?
int main (void)
// variable declarations
int sum; // for sum of two dice
char answer; // for yes/no questions
int tempTotal = 0;
int p1Total; //Running total for player 1
int p2Total; //Running total for player 2
int total = 0; //total before assigning to player 1 or 2
int die1 = 0;
int die2 = 0;
int currentPlayer = 1; // Start with Player 1
srand(time(NULL)); // seed random # generator
do // play at least one game
//give option to view the rules
printf("Welcome to the game of Pig. Would you like to view the rules? (y or n)?\n");
answer = getchar();
if (answer == 'y');