Thread: PRS Help

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Dec 2004
    Location
    Oklahoma City
    Posts
    55

    PRS Help

    I know ya'll have probably seen this one a thousand times but would appreciate some help. Here's the code:

    Header File:

    Code:
    /* The game of paper, rock, scissors. */
    
    #include <ctype.h>				/* for isspace() */
    #include <stdio.h>				/* for printf(), etc */
    #include <stdlib.h>				/* for rand() and srand() */
    #include <time.h>				/* for time() */
    
    enum p_r_s1	{paper, rock, scissors,
    			game, help, instructions, quit};
    
    enum outcome {win, lose, tie, error};
    
    typedef		enum p_r_s1		p_r_s1;
    typedef		enum outcome	outcome;
    
    outcome		compare(p_r_s1 player_choice, p_r_s1 machine_choice);
    void		prn_final_status(int win_cnt, int lose_cnt);
    void		prn_game_status(int win_cnt, int lose_cnt, int tie_cnt);
    
    void		prn_help(void);
    void		prn_instructions(void);
    void		report(outcome result, int *win_cnt_ptr, int *lose_cnt_ptr, int *tie_cnt_ptr);
    void		report(outcome result, char *player_choice, char *machine_choice);
    p_r_s1		selection_by_machine(void);
    p_r_s1		selection_by_player(void);
    Main File:

    Code:
    #include "p_r_s1.h"
    
    int main(void)
    {
       int       win_cnt = 0, lose_cnt = 0, tie_cnt = 0;
       outcome   result;
       p_r_s1    player_choice, machine_choice;
    
       srand(time(NULL));              /* seed the random number generator*/
       prn_instructions();
       while ((player_choice = selection_by_player()) != quit)
          switch (player_choice) {
          case paper:
          case rock:
          case scissors:
             machine_choice = selection_by_machine();
             result = compare(player_choice, machine_choice);
             report (result, &win_cnt, &lose_cnt, &tie_cnt);
    		 break;
          case game:
             prn_game_status(win_cnt, lose_cnt, tie_cnt);
             break;
          case instructions:
             prn_instructions();
             break;
          case help:
             prn_help();
             break;
          default:
             printf("\nPROGRAMMER ERROR: Cannot get to here!\n\n");
             exit(1);
          }
       prn_game_status(win_cnt, lose_cnt, tie_cnt);
       prn_final_status(win_cnt, lose_cnt);
       return 0;
    }
    Compare File:

    Code:
    #include "p_r_s1.h"
    
    outcome compare(p_r_s1 player_choice, p_r_s1 machine_choice)
    {
    	outcome		result;
    
    	if (player_choice == machine_choice)
    		return tie;
    	switch (player_choice) {
    		case paper:
    			result = (machine_choice == rock) ? win : lose;
    			break;
    		case rock:
    			result = (machine_choice == scissors) ? win : lose;
    			break;
    		case scissors:
    			result = (machine_choice == paper) ? win : lose;
    			break;
    		default:
    			printf("PROGRAMMING ERROR: Unexpected choice!\n\n");
    			exit(1);
    	}
    	return result;
    }
    Print File:

    Code:
    #include "p_r_s1.h"
    
    void prn_final_status(int win_cnt, int lose_cnt)
    {
    	if (win_cnt > lose_cnt)
    		printf("CONGRATULATIONS - You won!\n\n");
    	else if (win_cnt == lose_cnt)
    		printf("A DRAW - You tied!\n\n");
    	else
    		printf("SORRY - You lost!\n\n");
    }
    
    void prn_game_status(int win_cnt, int lose_cnt, int tie_cnt)
    {
    	printf("\n%s\n%s%4d\n%s%4d\n%s%4d\n%s%4d\n\n",
    		"GAME STATUS:",
    		"	Win:	", win_cnt,
    		"	Lose:	", lose_cnt,
    		"	Tie:	", tie_cnt,
    		"	Total:	", win_cnt + lose_cnt + tie_cnt);
    }
    
    void prn_help(void)
    {
    	printf("\n%s\n",
    		"The following characters can be used for input:\n"
    		"	p	for paper\n"
    		"	r	for rock\n"
    		"	s	for scissors\n"
    		"	g	print the game status\n"
    		"	h	help, print this list\n"
    		"	i	Reprint the instructions\n"
    		"	q	quit this game\n");
    }
    
    void prn_instructions(void)
    {
    	printf("\n%s\n",
    		"Paper, Rock, Scissors:\n"
    		"\n"
    		"In this game\n"
    		"\n"
    		"	p is for \"paper\"\n"
    		"	r is for \"rock\"\n"
    		"	s is for \"scissors\"\n"
    		"\n"
    		"Both the player and the machine will choose one\n"
    		"of p, r, or s. If the two choices are the same,\n"
    		"then the game is a tie. Otherwise:\n"
    		"\n"
    		"	\"paper covers the rock\"		(a win for paper)\n"
    		"	\"rock crushes the scissors\"	(a win for rock)\n"
    		"	\"scissors cut through paper\"	(a win for scissors)\n"
    		"\n"
    		"There are other allowable inputs:\n"
    		"\n"
    		"	g	for game status		(print number of wins)\n"
    		"	h	for help			(print short instructions)\n"
    		"	i	for instructions	(print these instructions)\n"
    		"	q	for quit			(quit the game)\n"
    		"\n"
    		"This game is played repeatedly until q is entered.\n"
    		"\n"
    		"Good Luck!\n");
    }
    Report File:

    Code:
    #include "p_r_s1.h"
    
    void report(outcome result, int *win_cnt_ptr, int *lose_cnt_ptr, int
    *tie_cnt_ptr, p_r_s1 player_choice, p_r_s1 machine_choice)
    { 
    	switch (result) {
      case win:
       ++*win_cnt_ptr;
       if (player_choice == paper)
        printf("%27sYou chose paper I chose rock.  You win.\n", "");
       else if (player_choice == rock)
        printf("%27sYou chose rock I chose scissors.  You win.\n", "");
       else if (player_choice == scissors)
        printf("%27sYou chose scissors I chose paper.  You win.\n", "");
       break;
      case lose:
       ++*lose_cnt_ptr;
       if (player_choice == paper)
        printf("%27sYou chose paper I chose scissors.  You lose.\n", "");
       else if (player_choice == rock)
        printf("%27sYou chose rock I chose paper.  You lose.\n", "");
       else if (player_choice == scissors)
        printf("%27sYou chose scissors I chose rock.  You lose.\n", "");
       break;
      case tie:
       ++*tie_cnt_ptr;
       if (player_choice == paper)
        printf("%27sYou chose paper I chose paper.  We tie.\n", "");
       else if (player_choice == rock)
        printf("%27sYou chose rock I chose rock.  We tie.\n", "");
       else if (player_choice == scissors)
        printf("%27sYou chose scissors I chose scissors.  We tie.\n", "");
       break;
      default:
       printf("PROGRAMMER ERROR: Unexpected result!\n\n");
       exit(1);
     
    	}
    }
    Select File:

    Code:
    #include "p_r_s1.h"
    
    p_r_s1	selection_by_machine(void)
    {
    	return ((p_r_s1) (rand() % 3));
    }
    p_r_s1	selection_by_player(void)
    {
    	char	c;
    	p_r_s1	player_choice;
    
    	printf("Input p, r, or s:   ");
    	scanf(" %c", &c);
    	switch (c) {
    		case 'p':
    			player_choice = paper;
    			break;
    		case 'r':
    			player_choice = rock;
    			break;
    		case 's':
    			player_choice = scissors;
    			break;
    		case 'g':
    			player_choice = game;
    			break;
    		case 'i':
    			player_choice = instructions;
    			break;
    		case 'q':
    			player_choice = quit;
    			break;
    		default:
    			player_choice = help;
    			break;
    	}
    	return player_choice;
    }
    I keep getting the following errors:

    main.cpp(9) : warning C4244: 'argument' : conversion from 'time_t' to 'unsigned int', possible loss of data

    Linking...

    main.obj : error LNK2019: unresolved external symbol "void __cdecl report(enum outcome,int *,int *,int *)" (?report@@YAXW4outcome@@PAH11@Z) referenced in function _main

    Debug/p_r_s1.exe : fatal error LNK1120: 1 unresolved externals

    I'm told that the function prototype and definition don't match number of items and correct types in the header and main files but I can't see where, my eyes hurt looking for it

    Thanks
    Last edited by SpudNuts; 12-01-2004 at 09:28 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Read/Write linked lists from/to file
    By XorpiZ in forum C Programming
    Replies: 35
    Last Post: 01-29-2005, 08:13 PM
  2. Multi-Threading and ADO
    By chandhru in forum Windows Programming
    Replies: 19
    Last Post: 05-15-2004, 11:53 AM