![]() |
| | #1 |
| Registered User Join Date: Sep 2008
Posts: 35
| Why do the rules for my game print when I tell them not to? Code: // function: prn_rules
// pre: none
// post: prints the rules
void prnRules(void)
{
printf("%s\n",
"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");
}
Code: 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();
getchar();
if (answer == 'y');
{
prnRules();
}
Thank you, crazychile |
| crazychile is offline | |
| | #2 |
| Chinese pâté Join Date: Jul 2007 Location: Canada
Posts: 406
| Code: if (answer == 'y');
__________________ I hate real numbers. |
| foxman is offline | |
| | #3 |
| Registered User Join Date: Sep 2008
Posts: 35
| Thanks foxman! It's not the first time I've done that. It might be time I made a post-it on that for the wall of shame. crazychile |
| crazychile is offline | |
| | #4 | |
| Mysterious C++ User Join Date: Oct 2007
Posts: 14,099
| Have you turned up your compiler warnings to max? Many compilers would warn about that. And your indentation is pretty poor, as well. You might want to fix that.
__________________ Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System I dedicated my life to helping others. This is only a small sample of what they said: "Thanks Elysia. You're a programming master! How the hell do you know every thing?" Quoted... at least once. Quote:
| |
| Elysia is offline | |
| | #5 |
| Registered User Join Date: Sep 2008
Posts: 35
| I know my indentation is messed up and I need to fix it. It looks fine on my screen but does strange stuff when I copy paste to the forum. How do I set my compiler warnings to max? I'm on a Mac running Xcode, that uses gcc. Thanks for the tip. crazychile |
| crazychile is offline | |
| | #6 | ||
| C++ Witch Join Date: Oct 2003 Location: Singapore
Posts: 10,365
| Quote:
Quote:
__________________ C + C++ Compiler: MinGW port of GCC Build + Version Control System: SCons + Bazaar Look up a C/C++ Reference and learn How To Ask Questions The Smart Way | ||
| laserlight is online now | |
| | #7 |
| Registered User Join Date: Sep 2008
Posts: 35
| Wow. Thanks! It appears that all I need to do in the terminal window on a Mac is: gcc filename -Wall |
| crazychile is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| 2D Game project requires extra C++ programmers, new or experienced | drallstars | Projects and Job Recruitment | 2 | 05-16-2007 10:46 AM |
| Game Independent Anti-cheat Project Needs Programmers | GIA Project Lea | Projects and Job Recruitment | 3 | 09-15-2005 07:41 PM |
| Engine <=> DX/OGL | c++ ? | darkcloud | Game Programming | 6 | 05-13-2005 12:19 AM |
| Game Designer vs Game Programmer | the dead tree | Game Programming | 8 | 04-28-2005 09:17 PM |
| how do the game engine and the api interact? | Shadow12345 | Game Programming | 7 | 06-05-2002 10:06 PM |