LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 10-16-2005, 05:40 PM   #1
Mistro116@yahoo.com
Member
 
Registered: Sep 2005
Posts: 118

Rep: Reputation: 15
Segementation Fault Error (Core Dumped) ???


Could anyone PLEASSSE help me figure out why im getting a segmentation fault (core dumped) runtime error when I run this?! Project is due in 6 hours, please help!!!

Code:
/***********************************************************
 *  Function: TestSlots
 *  Usage: TestSlots ();
 *
 *  This function will be responsible for storing and
 *  processing all of the input from the user, regarding
 *  simulating the main driver program in Test Mode. This
 *  function will manipulate two local array variables, int
 *  testSlotMachine [NUMBEROFSLOTMACHINEWHEELS], whose
 *  indices contain three random numbers between
 *  LOW, 0, and HIGH, 5, inclusively, and int winningResults
 *  [NUMBEROFWINNINGCOMBINATIONS], whose indices contain
 *  counters for the number of times each of the possible
 *  winning combinations were randomly obtained. This
 *  function will also be responsible for making calls to
 *  several functions that will perform and/or display the
 *  results of the processes of the main driver program in
 *  Test Mode.
 *
 *  This is a high level function that will perform in the
 *  following way:
 *
 *  This function will first prompt the user for the number
 *  of games that Test Mode should simulate, by making a
 *  call to NumberOfGames (), which will ensure that the
 *  number of games simulated in Test Mode is a positive
 *  integer that is 100,000 or less, or between
 *  MINNUMBEROFGAMES, 0, and MAXNUMBEROFGAMES, 100,000.
 *  The function will also prompt the user for a positive
 *  integer seed for the pseudo-random generator to be
 *  passed to, by making a call to GetPositiveSeed (),
 *  which will ensure that the positive seed is a positive
 *  integer between MINPOSITIVESEED, 1, and MAXPOSITIVESEED,
 *  65,000. After prompting the user for a positive integer
 *  seed for the pseudo-random number generator, this
 *  function makes a call to SetPositiveSeed (int
 *  positiveSeed), which seeds the pseudo-random number
 *  generator with the positive integer value returned from
 *  GetPositiveSeed (). Then, this function will make a
 *  call to SimulateNumberOfGames (int numberOfGames), which
 *  will call InitializeCounterArray (int winningResults
 *  [NUMBEROFWINNINGCOMBINATIONS]), which will initialize
 *  all of the indices of the local counter array variable,
 *  int winningResults [NUMBEROFWINNINGCOMBINATIONS], to 0
 *  before this function starts to progress through the
 *  for-loop. This function will also call the function
 *  TestPullSlotMachine () int numberOfGames amount of
 *  times, and will simulate the numberOfGames specified by
 *  the user. The function, TestPullSlotMachine, makes a
 *  call to SimulatePullSlotMachine (int testSlotMachine
 *  [NUMBEROFSLOTMACHINEWHEELS], which assigns a pseudo-
 *  random number between LOW, 0, and  HIGH, 5, into the 
 *  three indices of the local array variable, int
 *  testSlotMachine [NUMBEROFSLOTMACHINEWHEELS], and makes a
 *  call to TestGetSlotResults (int testSlotMachine
 *  [NUMBEROFSLOTMACHINEWHEELS], int winningResults
 *  [NUMBEROFWINNINGCOMBINATIONS]), which evaluates the
 *  three indices of the local array variable, int
 *  testSlotMachine[NUMBEROFSLOTMACHINEWHEELS], and checks
 *  to see if the order and the values of the three indices
 *  match any of the seven winning combinations by using
 *  three nested switch statements. If the switch statements
 *  match the three random numbers with one of the seven
 *  possible winning combinations, then the proper position
 *  of the second local array variable, int winningResults
 *  [NUMBEROFWINNINGCOMBINATIONS], denoting the winning
 *  combination that was detected by this function, will be
 *  incremented by 1. This is all repeated int numberOfGames
 *  amount of times through the call to the function,
 *  SimulateNumberOfGames (int numberOfGames). Then, the
 *  number of occurences of each of the possible winning
 *  combinations is displayed, as well as the number of
 *  losses, by making a call to the function,
 *  DisplayTestResults (int winningResults
 *  [NUMBEROFWINNINGCOMBINATIONS], int numberOfGames). Once
 *  these tasks have been executed, the user is returned to
 *  the main menu.
 *
 *  Input: None - this function takes void as its argument
 *                specifier/parameter.
 *  Output: None - this function takes a void return-type.
 *
 **********************************************************/

void TestSlots (void)
{
   /* A local variable array that will hold the values after
      each pull of the slot machine arm.                  */
   int testSlotMachine [NUMBEROFSLOTMACHINEWHEELS];
   
   /* A local variable array that will serve as a counter
      for the number of times a winning combination was
      produced.                                           */
   int winningResults [NUMBEROFWINNINGCOMBINATIONS];
   
   /*  Prompt the user to enter the number of games to be
       simulated, between MINNUMBEROFGAMES and
       MAXNUMBEROFGAMES.                                  */
   int numberOfGames = NumberOfGames ();
   
   /*  Prompt the user for the positive seed to be passed to
       the pseudo-random number generator, between
       MINPOSITIVESEED and MAXPOSITIVESEED.               */
   int positiveSeed = GetPositiveSeed ();
   
   /*  Seed the pseudo-random number generator with the
       positive seed entered by the user.                 */
   SetPositiveSeed(positiveSeed);
   
   /*  Initialize all of the indicies of the local counter
       array variable, int winningResults
       [NUMBEROFWINNINGCOMBINATIONS], to 0.               */
	    
   InitializeCounterArray (winningResults, 
			   NUMBEROFWINNINGCOMBINATIONS);
   
   /*  Simulate the number of games input by the user.    */
   SimulateNumberOfGames(numberOfGames, testSlotMachine,
			 winningResults);
}

/***********************************************************
 *  Function: NumberOfGames
 *  Usage: int numberOfGames = NumberOfGames (void);
 *
 *  This function will be responsible for prompting the user
 *  for and returning the number of games that the user
 *  indicates the Test Mode should simulate. This function
 *  will make a call to GetValidInt (MINNUMBEROFGAMES,
 *  MAXNUMBEROFGAMES), which will ensure that the number of
 *  games simulated in test mode is a positive integer that
 *  is 100,000 or less. This value, the number of games to
 *  be simulated, will be stored in the local variable, int
 *  numberOfGames.
 *
 *  Input: None - this function takes void as its argument
 *                specifier/parameter.
 *  Output: int numberOfGames - returns a valid integer
 *                              value, between
 *                              MINNUMBEROFGAMES, 0, and
 *                              MAXNUMBEROFGAMES, 100,000,
 *                              which corresponds to the
 *                              number of games to be
 *                              simulated in the Test Mode.
 *
 **********************************************************/

int NumberOfGames (void)
{
   int numberOfGames;
   
   /*  Prompt the user for the number of games to be
       simulated.                                         */
   printf ("How many times would you like to play the slots ?\n");
   printf ("Please enter an integer between %d and %d : ",
	   MINNUMBEROFGAMES, MAXNUMBEROFGAMES);
   
   /*  Allow the user to select the number of games to be
       simulated, between MINNUMBEROFGAMES and
       MAXNUMBEROFGAMES.                                  */
   numberOfGames = GetValidInt(MINNUMBEROFGAMES, 
			       MAXNUMBEROFGAMES);
   printf("\n\n");
   
   return numberOfGames;
}

/***********************************************************
 *  Function: GetPositiveSeed
 *  Usage: int positiveSeed = GetPositiveSeed (void);
 *
 *  This function will be responsible for prompting the user
 *  for and returning a positive integer seed for the
 *  pseudo-random number generator to simulate from in Test
 *  Mode. This function will make a call to GetValidInt
 *  (MINPOSITIVESEED, MAXPOSITIVESEED), which will ensure
 *  that the positive seed passed to the pseudo-random
 *  number generator in Test Mode is a positive integer
 *  value between MINPOSITIVESEED, 1, and MAXPOSITIVESEED,
 *  65,000. This value, the positive seed for the pseudo-
 *  random number generator to be passed to in Test Mode,
 *  will be stored in the local variable, int positiveSeed.
 *
 *  Input: None - this function takes void as its argument
 *                specifier/parameter.
 *  Output: int positiveSeed - returns a valid integer
 *                             value, between
 *                             MINPOSITIVESEED, 1, and
 *                             MAXPOSITIVESEED, 65,000,
 *                             which corresponds to the
 *                             positive integer seed value
 *                             for the pseuo-random number
 *                             generator to be passed in
 *                             Test Mode.
 *
 **********************************************************/

int GetPositiveSeed (void)
{
   int positiveSeed;
   
   /*  Prompt the user for the positive seed to be passed to
       the pseudo-random number generator.                */
   printf ("What positive number would you like to use as the seed ?\n");
   printf ("Please enter an integer between %d and %d : ",
	   MINPOSITIVESEED, MAXPOSITIVESEED);
   
   /*  Allow the user to select the positive integer to be
       passed to the pseudo-random number generator, between
       MINPOSITIVESEED and MAXPOSITIVESEED.               */
   positiveSeed = GetValidInt(MINPOSITIVESEED,
			      MAXPOSITIVESEED);
   printf("\n\n");
   
   return positiveSeed;
}

/***********************************************************
 *  Function: SetPositiveSeed
 *  Usage: SetPositiveSeed (int positiveSeed);
 *
 *  This function will be responsible for seeding the
 *  pseudo-random number generator with the positive integer
 *  value, between 1 and 65,000 inclusively, that was
 *  returned from GetPositiveSeed ().
 *
 *  Input: int positiveSeed - the positive integer value
 *                            between MINPOSITIVESEED, 1,
 *                            and MAXPOSITIVESEED, 65,000,
 *                            which corresponds to the
 *                            positive integer seed value
 *                            for the pseuo-random number
 *                            generator to be passed in
 *                            Test Mode.
 *  Output: None - this function takes a void return-type.
 *
 **********************************************************/

void SetPositiveSeed (int positiveSeed)
{
   srand (positiveSeed);
}

/***********************************************************
 *  Function: InitializeCounterArray
 *  Usage: InitializeCounterArray (int winningResults [ ],
 *                                 int numberOfWinningCombinations);
 *
 *  This function will be responsible for initializing all
 *  seven indicies of the local array variable, int
 *  winningResults [NUMBEROFWINNINGCOMBINATIONS], to 0, in
 *  order to allow it to be used as a counter.
 *
 *  Inputs: int winningResults [ ] -         a local array
 *                                           variable in
 *                                           TestSlots (),
 *                                           whose indices
 *                                           contain
 *                                           counters for
 *                                           the number of
 *                                           times each of
 *                                           the possible
 *                                           winning
 *                                           combinations
 *                                           were randomly
 *                                           obtained.
 *         int numberOfWinningCombinations - a constant that
 *                                           represents the
 *                                           number of
 *                                           elements in
 *                                           the local array
 *                                           variable,
 *                                           winningResults
 *                                           [ ].
 *  Output: None - this function takes a void return-type.
 *
 **********************************************************/

void InitializeCounterArray (int winningResults [ ], 
			     int numberOfWinningCombinations)
{
   int winningResultsIndex;
   
   for (winningResultsIndex = 0; winningResultsIndex < 
	NUMBEROFWINNINGCOMBINATIONS; winningResultsIndex++);
   {
      winningResults [winningResultsIndex] = 0;
   }
}

/***********************************************************
 *  Function: TestPullSlotMachine
 *  Usage: TestPullSlotMachine (void);
 *
 *  This function will be responsible for simulating one
 *  pull of the slot machine in Test Mode by calling
 *  SimulatePullSlotMachine (int testSlotMachine
 *  [NUMBEROFSLOTMACHINEWHEELS]), which will generate
 *  pseudo-random integers between LOW, 0, and HIGH, 5,
 *  inclusively, into the three indices of the local array
 *  variable, int testSlotMachine
 *  [NUMBEROFSLOTMACHINEWHEELS]. This function will also
 *  call TestGetSlotResults (), which will assign the
 *  winning combination, if it occured, into the proper
 *  position of the local array variable, int winningResults
 *  [NUMBEROFWINNINGCOMBINATIONS].
 *
 *  Inputs: int testSlotMachine [ ] - a local array variable
 *                                    in TestSlots (), whose
 *                                    indices contain three
 *                                    random numbers between
 *                                    LOW, 0, and HIGH, 5,
 *                                    inclusively.
 *         int winningResults [ ] -   a local array variable
 *                                    in TestSlots (), whose
 *                                    indices contain
 *                                    counters for the
 *                                    number of times each
 *                                    of the possible
 *                                    winning combinations
 *                                    were randomly
 *                                    obtained.
 *  Output: None - this function takes a void return-type.
 *
 **********************************************************/

void TestPullSlotMachine (int testSlotMachine [ ],
			  int winningResults [ ])
{
   SimulatePullSlotMachine(testSlotMachine, 
			   NUMBEROFSLOTMACHINEWHEELS);
   
   TestGetSlotResults(testSlotMachine, winningResults);
}

/***********************************************************
 *  Function: SimulatePullSlotMachine
 *  Usage: SimulatePullSlotMachine (int testSlotMachine [ ],
 *                                  int numberOfSlotMachineWheels);
 *
 *  This function will be responsible for assigning the
 *  the value of three random numbers between
 *  LOW, 0, and HIGH, 5, into the three indicies of the
 *  local array variable, int testSlotMachine
 *  [NUMBEROFSLOTMACHINEWHEELS].
 *
 *  Inputs: int testSlotMachine [ ] -      a local array
 *                                         variable in
 *                                         TestSlots(),
 *                                         whose contain
 *                                         three random
 *                                         numbers between
 *                                         LOW, 0, and HIGH,
 *				           5, inclusively.
 *         int numberOfSlotMachineWheels - a constant that
 *                                         represents the
 *                                         number of
 *                                         elements in
 *                                         the local array
 *                                         variable,
 *                                         testSlotMachine
 *                                         [ ].
 *  Output: None - this function takes a void return-type.
 *
 **********************************************************/

void SimulatePullSlotMachine (int testSlotMachine [ ], 
			      int numberOfSlotMachineWheels)
{
   int testSlotMachineIndex;
   
   for (testSlotMachineIndex = 0; testSlotMachineIndex <
	numberOfSlotMachineWheels; testSlotMachine++)
   {
      testSlotMachine [testSlotMachineIndex] =
	 GetRandomNumber ();
   }
}

/***********************************************************
 *  Function: TestGetSlotResults
 *  Usage: TestGetSlotResults (int testSlotMachine [ ],
 *                             int winningResults [ ]);
 *
 *  This function will be responsible for evaluating the
 *  three indices of local array variable, int
 *  testSlotMachine [NUMBEROFSLOTMACHINEWHEELS], and
 *  checking to see if the order and the values of the three
 *  indices match any of the seven winning combinations by
 *  using three nested switch statements. If the switch
 *  statements match the three random numbers with one of
 *  the seven possible winning combinations, then the proper
 *  position of the second local array variable, int
 *  winningResults [NUMBEROFWINNINGCOMBINATIONS], denoting
 *  the winning combination that was detected by this
 *  function, will be incremented by one.
 *
 *  Inputs: int testSlotMachine [ ] - a local array variable
 *                                    in TestSlots (), whose
 *                                    indices contain three
 *                                    random numbers between
 *                                    LOW, 0, and HIGH, 5,
 *                                    inclusively.
 *         int winningResults [ ] -   a local array variable
 *                                    in TestSlots (), whose
 *                                    indices contain
 *                                    counters for the
 *                                    number of times each
 *                                    of the possible
 *                                    winning combinations
 *                                    were randomly
 *                                    obtained.
 *  Output: None - this function takes a void return-type.
 *
 **********************************************************/

void TestGetSlotResults (int testSlotMachine [ ],
			 int winningResults [ ])
{
   switch (testSlotMachine [0])
   {
      case LEMON:
	 break;
      case CHERRY:
	 winningResults [0]++;
	 switch (testSlotMachine [1])
	 {
	    case LEMON:
	       break;
	    case CHERRY:
	       winningResults [1]++;
	       switch (testSlotMachine [2])
	       {
		  case LEMON:
		     break;
		  case CHERRY:
		     winningResults [2]++;
		     break;
		  case ORANGE:
		     break;
		  case PLUM:
		     break;
		  case BELL:
		     break;
		  case BAR:
		     break;
	       }
	       break;
	    case ORANGE:
	       break;
	    case PLUM:
	       break;
	    case BELL:
	       break;
	    case BAR:
	       break;
	 }
	 break;
      case ORANGE:
	 switch (testSlotMachine [1])
	 {
	    case LEMON:
	       break;
	    case CHERRY:
	       break;
	    case ORANGE:
	       switch (testSlotMachine [2])
	       {
		  case LEMON:
		     break;
		  case CHERRY:
		     break;
		  case ORANGE:
		     winningResults [3]++;
		     break;
		  case PLUM:
		     break;
		  case BELL:
		     break;
		  case BAR:
		     winningResults [3]++;
		     break;
	       }
	       break;
	    case PLUM:
	       break;
	    case BELL:
	       break;
	    case BAR:
	       break;
	 }
	 break;
      case PLUM:
	 switch (testSlotMachine [1])
	 {
	    case LEMON:
	       break;
	    case CHERRY:
	       break;
	    case ORANGE:
	       break;
	    case PLUM:
	       switch (testSlotMachine [2])
	       {
		  case LEMON:
		     break;
		  case CHERRY:
		     break;
		  case ORANGE:
		     break;
		  case PLUM:
		     winningResults [4]++;
		     break;
		  case BELL:
		     break;
		  case BAR:
		     winningResults [4]++;
		     break;
	       }
	       break;
	    case BELL:
	       break;
	    case BAR:
	       break;
	 }
	 break;
      case BELL:
	 switch (testSlotMachine [1])
	 {
	    case LEMON:
	       break;
	    case CHERRY:
	       break;
	    case ORANGE:
	       break;
	    case PLUM:
	       break;
	    case BELL:
	       switch (testSlotMachine [2])
	       {
		  case LEMON:
		     break;
		  case CHERRY:
		     break;
		  case ORANGE:
		     break;
		  case PLUM:
		     break;
		  case BELL:
		     winningResults [5]++;
		     break;
		  case BAR:
		     winningResults [5]++;
		     break;
	       }
	       break;
	    case BAR:
	       break;
	 }
	 break;
      case BAR:
	 switch (testSlotMachine [1])
	 {
	    case LEMON:
	       break;
	    case CHERRY:
	       break;
	    case ORANGE:
	       break;
	    case PLUM:
	       break;
	    case BELL:
	       break;
	    case BAR:
	       switch (testSlotMachine [2])
	       {
		  case LEMON:
		     break;
		  case CHERRY:
		     break;
		  case ORANGE:
		     break;
		  case PLUM:
		     break;
		  case BELL:
		     break;
		  case BAR:
		     winningResults [6]++;
		     break;
	       }
	 }
	 break;
   }
}

/***********************************************************
 *  Function: SimulateNumberOfGames
 *  Usage: SimulateNumberOfGames (int numberOfGames)
 *
 *  This function will be responsible for simulating the
 *  number of games input by the user, by using a for-loop
 *  and calling TestPullSlotMachine (). The for-loop will
 *  call TestPullSlotMachine () int numberOfGames times.
 *  This function will also call InitializeCounterArray (int
 *  winningResults [NUMBEROFWINNINGCOMBINATIONS] only once,
 *  before the start of the for-loop that will simulate the
 *  number of games in Test Mode, in order to initialize the
 *  all indices of the counter array to 0.
 *
 *  Inputs: int numberOfGames -       a valid integer value
 *                                    between MINNUMBEROFGAMES,
 *                                    0, and MAXNUMBEROFGAMES,
 *                                    100,000, which
 *                                    corresponds to the
 *                                    number of games to be
 *                                    simulated in the Test
 *                                    Mode.
 *          int testSlotMachine [ ] - a local array variable
 *                                    in TestSlots (), whose
 *                                    indices contain three
 *                                    random numbers between
 *                                    LOW, 0, and HIGH, 5,
 *                                    inclusively.
 *         int winningResults [ ] -   a local array variable
 *                                    in TestSlots (), whose
 *                                    indices contain
 *                                    counters for the
 *                                    number of times each
 *                                    of the possible
 *                                    winning combinations
 *                                    were randomly
 *                                    obtained.
 *  Output: None - this function takes a void return-type.
 *
 **********************************************************/

void SimulateNumberOfGames (int numberOfGames,
			    int testSlotMachine [ ],
			    int winningResults [ ])
{
   int numberOfGamesIndex;
   
   for (numberOfGamesIndex = 0; numberOfGamesIndex <
	numberOfGames; numberOfGamesIndex++)
   {
      TestPullSlotMachine(testSlotMachine, winningResults);
   }
}
 
Old 10-16-2005, 05:48 PM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,415

Rep: Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968
you really need to be using gdb to debug core dumps... could be a whole bunch of things. run the app through gdb, when it crashes, the backtrace "bt" will show what it was doing at the time. more often thatn not it's memory related in my experience.
 
Old 10-16-2005, 06:00 PM   #3
Hivemind
Member
 
Registered: Sep 2004
Posts: 273

Rep: Reputation: 30
Yes, you should debug and try to condense the code as much as possible to come up with a complete, compilable example that still exhibits the segfault you're seeing. Even though you posted a lot of code it was obviously not the complete program because it's clearly missing a bunch of declarations, defines and includes. You should also have posted more details on the crash, where did it occur? What is the expected output given a specific set of input etc?
 
Old 10-16-2005, 06:06 PM   #4
Mistro116@yahoo.com
Member
 
Registered: Sep 2005
Posts: 118

Original Poster
Rep: Reputation: 15
it occurred after i called testslots in my mainfile... it was supposed to tally the results in the array winningResults, but instead I get a segmentation error. Ive been trying to trace through it, im clueless I REALLY need some further help...
 
Old 10-16-2005, 06:17 PM   #5
Hivemind
Member
 
Registered: Sep 2004
Posts: 273

Rep: Reputation: 30
If you don't care to condense the code to a more compact test case you should at least post what's missing in the code for it to compile.
 
Old 10-16-2005, 06:38 PM   #6
Mistro116@yahoo.com
Member
 
Registered: Sep 2005
Posts: 118

Original Poster
Rep: Reputation: 15
This is the entire slot.c file as of right now, I tried to reduce the switch statement and cases to just do it directly, it didnt work, i tried to get rid of the simulatenumberofgames function didnt work... i tried everything. All the main does is TestSlots ( ); This is everything

Code:
/*  Slot machine item constants  */

#define LEMON                        0       /*  Slot
						 machine
						 item 0,
						 LEMON.   */
#define CHERRY                       1       /*  Slot
						 machine
						 item 1,
						 CHERRY.  */
#define ORANGE                       2       /*  Slot
						 machine
						 item 2,
						 ORANGE.  */
#define PLUM                         3       /*  Slot
						 machine
						 item 3,
						 PLUM.    */
#define BELL                         4       /*  Slot
						 machine
						 item 4,
						 BELL.    */
#define BAR                          5       /*  Slot
						 machine
						 item 5,
						 BAR.     */

/*  Number of games constants  */

#define MINNUMBEROFGAMES             0      /*   The minimum
						 number of
						 games that
						 can be
						 simulated
						 in Test
						 Mode,
						 0.       */
#define MAXNUMBEROFGAMES             100000  /*  The maximum
						 number of
						 games that
						 can be
						 simulated
						 in Test
						 Mode,
						 100,000. */

/*  Test mode positive seed constants  */

#define MINPOSITIVESEED              1       /*  The minimum
						 positive
						 seed that
						 can be
						 input by
						 the user
						 for the
						 pseudo-
						 random
						 number
						 generator,
						 1.       */
#define MAXPOSITIVESEED             65000    /*  The maximum
						 positive
						 seed that
						 can be
						 input by
						 the user
						 for the
						 pseudo-
						 random
						 number
						 generator,
						 65,000.  */

/*  Array size constants  */

#define NUMBEROFSLOTMACHINEWHEELS    3       /*  The total
						 number of
						 slot
						 machine
						 wheels,
						 3.       */ 
#define NUMBEROFWINNINGCOMBINATIONS  7       /*  The number
						 of possible
						 winning
						 patterns
						 that can be
						 produced
						 from the
						 slot
						 machine,
						 7.       */

/*  Play mode player stakes constants  */

#define INITIALSTAKEOFPLAYER         50      /*  The initial
						 stake of
						 the player
						 when first
						 beginning
						 Play Mode,
						 50.      */
#define LOSINGSTAKEOFPLAYER          0       /*  The losing
						 stake of
						 the player,
						 when Play
						 Mode will
						 terminate,
						 0.       */

/*  Play mode menu constants  */

#define MINPLAYMODEMENU              1       /*  The minimum
						 acceptable
						 choice from
						 the play
						 mode menu,
						 Option 1,
						 PLAYMODE
						 READ
					         INSTRUCTIONS.
						          */
#define PLAYMODEREADINSTRUCTIONS     1       /*  Option 1,
						 from the
						 play mode
						 menu,
						 PLAYMODE
						 READ
					         INSTRUCTIONS.
						          */
#define PLAYMODEPULLTHEARM           2       /*  Option 2,
						 from the
						 play mode
						 menu,
						 PLAYMODE
						 PULL THE
					         ARM.     */
#define PLAYMODEQUIT                 3       /*  Option 3,
						 from the
						 play mode
						 menu,
						 PLAYMODE
					         QUIT.    */
#define MAXPLAYMODEMENU		     3       /*  The maximum
						 acceptable
						 choice from
						 the play
						 mode menu,
						 Option 3,
						 PLAYMODE
						 QUIT.    */

/***********************************************************
 *
 *  The following function implementations and definitions
 *  are listed as hide details functions:
 *
 **********************************************************/


/***********************************************************
 *  Function: TestSlots
 *  Usage: TestSlots ();
 *
 *  This function will be responsible for storing and
 *  processing all of the input from the user, regarding
 *  simulating the main driver program in Test Mode. This
 *  function will manipulate two local array variables, int
 *  testSlotMachine [NUMBEROFSLOTMACHINEWHEELS], whose
 *  indices contain three random numbers between
 *  LOW, 0, and HIGH, 5, inclusively, and int winningResults
 *  [NUMBEROFWINNINGCOMBINATIONS], whose indices contain
 *  counters for the number of times each of the possible
 *  winning combinations were randomly obtained. This
 *  function will also be responsible for making calls to
 *  several functions that will perform and/or display the
 *  results of the processes of the main driver program in
 *  Test Mode.
 *
 *  This is a high level function that will perform in the
 *  following way:
 *
 *  This function will first prompt the user for the number
 *  of games that Test Mode should simulate, by making a
 *  call to NumberOfGames (), which will ensure that the
 *  number of games simulated in Test Mode is a positive
 *  integer that is 100,000 or less, or between
 *  MINNUMBEROFGAMES, 0, and MAXNUMBEROFGAMES, 100,000.
 *  The function will also prompt the user for a positive
 *  integer seed for the pseudo-random generator to be
 *  passed to, by making a call to GetPositiveSeed (),
 *  which will ensure that the positive seed is a positive
 *  integer between MINPOSITIVESEED, 1, and MAXPOSITIVESEED,
 *  65,000. After prompting the user for a positive integer
 *  seed for the pseudo-random number generator, this
 *  function makes a call to SetPositiveSeed (int
 *  positiveSeed), which seeds the pseudo-random number
 *  generator with the positive integer value returned from
 *  GetPositiveSeed (). Then, this function will make a
 *  call to SimulateNumberOfGames (int numberOfGames), which
 *  will call InitializeCounterArray (int winningResults
 *  [NUMBEROFWINNINGCOMBINATIONS]), which will initialize
 *  all of the indices of the local counter array variable,
 *  int winningResults [NUMBEROFWINNINGCOMBINATIONS], to 0
 *  before this function starts to progress through the
 *  for-loop. This function will also call the function
 *  TestPullSlotMachine () int numberOfGames amount of
 *  times, and will simulate the numberOfGames specified by
 *  the user. The function, TestPullSlotMachine, makes a
 *  call to SimulatePullSlotMachine (int testSlotMachine
 *  [NUMBEROFSLOTMACHINEWHEELS], which assigns a pseudo-
 *  random number between LOW, 0, and  HIGH, 5, into the 
 *  three indices of the local array variable, int
 *  testSlotMachine [NUMBEROFSLOTMACHINEWHEELS], and makes a
 *  call to TestGetSlotResults (int testSlotMachine
 *  [NUMBEROFSLOTMACHINEWHEELS], int winningResults
 *  [NUMBEROFWINNINGCOMBINATIONS]), which evaluates the
 *  three indices of the local array variable, int
 *  testSlotMachine[NUMBEROFSLOTMACHINEWHEELS], and checks
 *  to see if the order and the values of the three indices
 *  match any of the seven winning combinations by using
 *  three nested switch statements. If the switch statements
 *  match the three random numbers with one of the seven
 *  possible winning combinations, then the proper position
 *  of the second local array variable, int winningResults
 *  [NUMBEROFWINNINGCOMBINATIONS], denoting the winning
 *  combination that was detected by this function, will be
 *  incremented by 1. This is all repeated int numberOfGames
 *  amount of times through the call to the function,
 *  SimulateNumberOfGames (int numberOfGames). Then, the
 *  number of occurences of each of the possible winning
 *  combinations is displayed, as well as the number of
 *  losses, by making a call to the function,
 *  DisplayTestResults (int winningResults
 *  [NUMBEROFWINNINGCOMBINATIONS], int numberOfGames). Once
 *  these tasks have been executed, the user is returned to
 *  the main menu.
 *
 *  Input: None - this function takes void as its argument
 *                specifier/parameter.
 *  Output: None - this function takes a void return-type.
 *
 **********************************************************/

void TestSlots (void)
{
   /* A local variable array that will hold the values after
      each pull of the slot machine arm.                  */
   int testSlotMachine [NUMBEROFSLOTMACHINEWHEELS];
   
   /* A local variable array that will serve as a counter
      for the number of times a winning combination was
      produced.                                           */
   int winningResults [NUMBEROFWINNINGCOMBINATIONS];
   
   /*  Prompt the user to enter the number of games to be
       simulated, between MINNUMBEROFGAMES and
       MAXNUMBEROFGAMES.                                  */
   int numberOfGames = NumberOfGames ();
   
   /*  Prompt the user for the positive seed to be passed to
       the pseudo-random number generator, between
       MINPOSITIVESEED and MAXPOSITIVESEED.               */
   int positiveSeed = GetPositiveSeed ();
   
   /*  Seed the pseudo-random number generator with the
       positive seed entered by the user.                 */
   SetPositiveSeed(positiveSeed);
   
   /*  Initialize all of the indicies of the local counter
       array variable, int winningResults
       [NUMBEROFWINNINGCOMBINATIONS], to 0.               */
	    
   InitializeCounterArray (winningResults, 
			   NUMBEROFWINNINGCOMBINATIONS);
   
   /*  Simulate the number of games input by the user.    */
   int i;
   for (i = 0; i < numberOfGames; i++)
   {
      SimulatePullSlotMachine (testSlotMachine,
			       NUMBEROFSLOTMACHINEWHEELS);
      
      TestGetSlotResults (testSlotMachine, winningResults);
   }
   
   DisplayTestResults (winningResults, 
		       NUMBEROFWINNINGCOMBINATIONS,
		       numberOfGames);
}

/***********************************************************
 *  Function: NumberOfGames
 *  Usage: int numberOfGames = NumberOfGames (void);
 *
 *  This function will be responsible for prompting the user
 *  for and returning the number of games that the user
 *  indicates the Test Mode should simulate. This function
 *  will make a call to GetValidInt (MINNUMBEROFGAMES,
 *  MAXNUMBEROFGAMES), which will ensure that the number of
 *  games simulated in test mode is a positive integer that
 *  is 100,000 or less. This value, the number of games to
 *  be simulated, will be stored in the local variable, int
 *  numberOfGames.
 *
 *  Input: None - this function takes void as its argument
 *                specifier/parameter.
 *  Output: int numberOfGames - returns a valid integer
 *                              value, between
 *                              MINNUMBEROFGAMES, 0, and
 *                              MAXNUMBEROFGAMES, 100,000,
 *                              which corresponds to the
 *                              number of games to be
 *                              simulated in the Test Mode.
 *
 **********************************************************/

int NumberOfGames (void)
{
   int numberOfGames;
   
   /*  Prompt the user for the number of games to be
       simulated.                                         */
   printf ("How many times would you like to play the slots ?\n");
   printf ("Please enter an integer between %d and %d : ",
	   MINNUMBEROFGAMES, MAXNUMBEROFGAMES);
   
   /*  Allow the user to select the number of games to be
       simulated, between MINNUMBEROFGAMES and
       MAXNUMBEROFGAMES.                                  */
   numberOfGames = GetValidInt(MINNUMBEROFGAMES, 
			       MAXNUMBEROFGAMES);
   printf("\n\n");
   
   return numberOfGames;
}

/***********************************************************
 *  Function: GetPositiveSeed
 *  Usage: int positiveSeed = GetPositiveSeed (void);
 *
 *  This function will be responsible for prompting the user
 *  for and returning a positive integer seed for the
 *  pseudo-random number generator to simulate from in Test
 *  Mode. This function will make a call to GetValidInt
 *  (MINPOSITIVESEED, MAXPOSITIVESEED), which will ensure
 *  that the positive seed passed to the pseudo-random
 *  number generator in Test Mode is a positive integer
 *  value between MINPOSITIVESEED, 1, and MAXPOSITIVESEED,
 *  65,000. This value, the positive seed for the pseudo-
 *  random number generator to be passed to in Test Mode,
 *  will be stored in the local variable, int positiveSeed.
 *
 *  Input: None - this function takes void as its argument
 *                specifier/parameter.
 *  Output: int positiveSeed - returns a valid integer
 *                             value, between
 *                             MINPOSITIVESEED, 1, and
 *                             MAXPOSITIVESEED, 65,000,
 *                             which corresponds to the
 *                             positive integer seed value
 *                             for the pseuo-random number
 *                             generator to be passed in
 *                             Test Mode.
 *
 **********************************************************/

int GetPositiveSeed (void)
{
   int positiveSeed;
   
   /*  Prompt the user for the positive seed to be passed to
       the pseudo-random number generator.                */
   printf ("What positive number would you like to use as the seed ?\n");
   printf ("Please enter an integer between %d and %d : ",
	   MINPOSITIVESEED, MAXPOSITIVESEED);
   
   /*  Allow the user to select the positive integer to be
       passed to the pseudo-random number generator, between
       MINPOSITIVESEED and MAXPOSITIVESEED.               */
   positiveSeed = GetValidInt(MINPOSITIVESEED,
			      MAXPOSITIVESEED);
   printf("\n\n");
   
   return positiveSeed;
}

/***********************************************************
 *  Function: SetPositiveSeed
 *  Usage: SetPositiveSeed (int positiveSeed);
 *
 *  This function will be responsible for seeding the
 *  pseudo-random number generator with the positive integer
 *  value, between 1 and 65,000 inclusively, that was
 *  returned from GetPositiveSeed ().
 *
 *  Input: int positiveSeed - the positive integer value
 *                            between MINPOSITIVESEED, 1,
 *                            and MAXPOSITIVESEED, 65,000,
 *                            which corresponds to the
 *                            positive integer seed value
 *                            for the pseuo-random number
 *                            generator to be passed in
 *                            Test Mode.
 *  Output: None - this function takes a void return-type.
 *
 **********************************************************/

void SetPositiveSeed (int positiveSeed)
{
   srand (positiveSeed);
}

/***********************************************************
 *  Function: InitializeCounterArray
 *  Usage: InitializeCounterArray (int winningResults [ ],
 *                                 int numberOfWinningCombinations);
 *
 *  This function will be responsible for initializing all
 *  seven indicies of the local array variable, int
 *  winningResults [NUMBEROFWINNINGCOMBINATIONS], to 0, in
 *  order to allow it to be used as a counter.
 *
 *  Inputs: int winningResults [ ] -         a local array
 *                                           variable in
 *                                           TestSlots (),
 *                                           whose indices
 *                                           contain
 *                                           counters for
 *                                           the number of
 *                                           times each of
 *                                           the possible
 *                                           winning
 *                                           combinations
 *                                           were randomly
 *                                           obtained.
 *         int numberOfWinningCombinations - a constant that
 *                                           represents the
 *                                           number of
 *                                           elements in
 *                                           the local array
 *                                           variable,
 *                                           winningResults
 *                                           [ ].
 *  Output: None - this function takes a void return-type.
 *
 **********************************************************/

void InitializeCounterArray (int winningResults [ ], 
			     int numberOfWinningCombinations)
{
   int winningResultsIndex;
   
   for (winningResultsIndex = 0; winningResultsIndex < 
	NUMBEROFWINNINGCOMBINATIONS; winningResultsIndex++);
   {
      winningResults [winningResultsIndex] = 0;
   }
}

/***********************************************************
 *  Function: TestPullSlotMachine
 *  Usage: TestPullSlotMachine (int testSlotMachine [ ],
 *                                  int winningResults [ ]);
 *
 *  This function will be responsible for simulating one
 *  pull of the slot machine in Test Mode by calling
 *  SimulatePullSlotMachine (int testSlotMachine
 *  [NUMBEROFSLOTMACHINEWHEELS]), which will generate
 *  pseudo-random integers between LOW, 0, and HIGH, 5,
 *  inclusively, into the three indices of the local array
 *  variable, int testSlotMachine
 *  [NUMBEROFSLOTMACHINEWHEELS]. This function will also
 *  call TestGetSlotResults (), which will assign the
 *  winning combination, if it occured, into the proper
 *  position of the local array variable, int winningResults
 *  [NUMBEROFWINNINGCOMBINATIONS].
 *
 *  Inputs: int testSlotMachine [ ] - a local array variable
 *                                    in TestSlots (), whose
 *                                    indices contain three
 *                                    random numbers between
 *                                    LOW, 0, and HIGH, 5,
 *                                    inclusively.
 *         int winningResults [ ] -   a local array variable
 *                                    in TestSlots (), whose
 *                                    indices contain
 *                                    counters for the
 *                                    number of times each
 *                                    of the possible
 *                                    winning combinations
 *                                    were randomly
 *                                    obtained.
 *  Output: None - this function takes a void return-type.
 *
 **********************************************************/

void TestPullSlotMachine (int testSlotMachine [ ],
			  int winningResults [ ])
{
   SimulatePullSlotMachine(testSlotMachine, 
			   NUMBEROFSLOTMACHINEWHEELS);
   
   TestGetSlotResults(testSlotMachine, winningResults);
}


void SimulatePullSlotMachine (int testSlotMachine [ ], 
			      int numberOfSlotMachineWheels)
{
   int testSlotMachineIndex;
   
   for (testSlotMachineIndex = 0; testSlotMachineIndex <
	numberOfSlotMachineWheels; testSlotMachine++)
   {
      testSlotMachine [testSlotMachineIndex] =
	 GetRandomNumber ();
   }
}

/***********************************************************
 *  Function: TestGetSlotResults
 *  Usage: TestGetSlotResults (int testSlotMachine [ ],
 *                             int winningResults [ ]);
 *
 *  This function will be responsible for evaluating the
 *  three indices of local array variable, int
 *  testSlotMachine [NUMBEROFSLOTMACHINEWHEELS], and
 *  checking to see if the order and the values of the three
 *  indices match any of the seven winning combinations by
 *  using three nested switch statements. If the switch
 *  statements match the three random numbers with one of
 *  the seven possible winning combinations, then the proper
 *  position of the second local array variable, int
 *  winningResults [NUMBEROFWINNINGCOMBINATIONS], denoting
 *  the winning combination that was detected by this
 *  function, will be incremented by one.
 *
 *  Inputs: int testSlotMachine [ ] - a local array variable
 *                                    in TestSlots (), whose
 *                                    indices contain three
 *                                    random numbers between
 *                                    LOW, 0, and HIGH, 5,
 *                                    inclusively.
 *         int winningResults [ ] -   a local array variable
 *                                    in TestSlots (), whose
 *                                    indices contain
 *                                    counters for the
 *                                    number of times each
 *                                    of the possible
 *                                    winning combinations
 *                                    were randomly
 *                                    obtained.
 *  Output: None - this function takes a void return-type.
 *
 **********************************************************/

void TestGetSlotResults (int testSlotMachine [ ],
			 int winningResults [ ])
{
   switch (testSlotMachine [0])
   {
      case LEMON:
	 break;
      case CHERRY:
	 winningResults [0]++;
	 switch (testSlotMachine [1])
	 {
	    case LEMON:
	       break;
	    case CHERRY:
	       winningResults [1]++;
	       switch (testSlotMachine [2])
	       {
		  case LEMON:
		     break;
		  case CHERRY:
		     winningResults [2]++;
		     break;
		  case ORANGE:
		     break;
		  case PLUM:
		     break;
		  case BELL:
		     break;
		  case BAR:
		     break;
	       }
	       break;
	    case ORANGE:
	       break;
	    case PLUM:
	       break;
	    case BELL:
	       break;
	    case BAR:
	       break;
	 }
	 break;
      case ORANGE:
	 switch (testSlotMachine [1])
	 {
	    case LEMON:
	       break;
	    case CHERRY:
	       break;
	    case ORANGE:
	       switch (testSlotMachine [2])
	       {
		  case LEMON:
		     break;
		  case CHERRY:
		     break;
		  case ORANGE:
		     winningResults [3]++;
		     break;
		  case PLUM:
		     break;
		  case BELL:
		     break;
		  case BAR:
		     winningResults [3]++;
		     break;
	       }
	       break;
	    case PLUM:
	       break;
	    case BELL:
	       break;
	    case BAR:
	       break;
	 }
	 break;
      case PLUM:
	 switch (testSlotMachine [1])
	 {
	    case LEMON:
	       break;
	    case CHERRY:
	       break;
	    case ORANGE:
	       break;
	    case PLUM:
	       switch (testSlotMachine [2])
	       {
		  case LEMON:
		     break;
		  case CHERRY:
		     break;
		  case ORANGE:
		     break;
		  case PLUM:
		     winningResults [4]++;
		     break;
		  case BELL:
		     break;
		  case BAR:
		     winningResults [4]++;
		     break;
	       }
	       break;
	    case BELL:
	       break;
	    case BAR:
	       break;
	 }
	 break;
      case BELL:
	 switch (testSlotMachine [1])
	 {
	    case LEMON:
	       break;
	    case CHERRY:
	       break;
	    case ORANGE:
	       break;
	    case PLUM:
	       break;
	    case BELL:
	       switch (testSlotMachine [2])
	       {
		  case LEMON:
		     break;
		  case CHERRY:
		     break;
		  case ORANGE:
		     break;
		  case PLUM:
		     break;
		  case BELL:
		     winningResults [5]++;
		     break;
		  case BAR:
		     winningResults [5]++;
		     break;
	       }
	       break;
	    case BAR:
	       break;
	 }
	 break;
      case BAR:
	 switch (testSlotMachine [1])
	 {
	    case LEMON:
	       break;
	    case CHERRY:
	       break;
	    case ORANGE:
	       break;
	    case PLUM:
	       break;
	    case BELL:
	       break;
	    case BAR:
	       switch (testSlotMachine [2])
	       {
		  case LEMON:
		     break;
		  case CHERRY:
		     break;
		  case ORANGE:
		     break;
		  case PLUM:
		     break;
		  case BELL:
		     break;
		  case BAR:
		     winningResults [6]++;
		     break;
	       }
	 }
	 break;
   }
}

/***********************************************************
 *  Function: SimulateNumberOfGames
 *  Usage: SimulateNumberOfGames (int numberOfGames)
 *
 *  /
void SimulateNumberOfGames (int numberOfGames,
			    int testSlotMachine [ ],
			    int winningResults [ ])
{
   int numberOfGamesIndex;
   
   for (numberOfGamesIndex = 0; numberOfGamesIndex <
	numberOfGames; numberOfGamesIndex++)
   {
      TestPullSlotMachine(testSlotMachine, winningResults);
   }
}
 
Old 10-16-2005, 06:58 PM   #7
Hivemind
Member
 
Registered: Sep 2004
Posts: 273

Rep: Reputation: 30
You know, if that's the complete source as you claim it is, I would first compile the program with all warnings turned on and fix all warnings about implicit declarations to start with.
 
Old 10-17-2005, 05:11 AM   #8
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Mint, Puppy
Posts: 3,314

Rep: Reputation: 175Reputation: 175
I had a quick look,
I got:

Code:
1.c:409: error: conflicting types for 'SetPositiveSeed'
1.c:267: error: previous implicit declaration of 'SetPositiveSeed' was here
1.c:450: error: conflicting types for 'InitializeCounterArray'
1.c:273: error: previous implicit declaration of 'InitializeCounterArray' was here
1.c:509: error: conflicting types for 'SimulatePullSlotMachine'
1.c:280: error: previous implicit declaration of 'SimulatePullSlotMachine' was here
1.c:559: error: conflicting types for 'TestGetSlotResults'
1.c:283: error: previous implicit declaration of 'TestGetSlotResults' was here
1.c:736:1: unterminated comment
You've got implicit declarations. You should put your function prototypes in a
header or at the top.

get rid of these warnings and errors first.
 
Old 10-17-2005, 12:10 PM   #9
Mistro116@yahoo.com
Member
 
Registered: Sep 2005
Posts: 118

Original Poster
Rep: Reputation: 15
It actually turned out to be a infinite loop error in one of my for-loops... pretty surprising...

When i was messing around with variable names, i saw it and fixed it... works great, thanks for ur help.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Segmentation fault (core dumped) eytan *BSD 3 04-27-2005 09:38 PM
Segmentation Fault (core dumped) newuser455 Linux - Software 3 08-28-2004 03:39 PM
Segmentation fault (core dumped) plisken Linux - General 8 09-17-2003 04:32 AM
Segmentation fault (core dumped) hasanaydin Linux - General 0 03-27-2002 08:47 AM
what is segmantation fault (core dumped) jolly Linux - General 5 10-01-2001 10:03 AM


All times are GMT -5. The time now is 04:56 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration