need help with rock paper scissors program

This is a discussion on need help with rock paper scissors program within the C Programming forums, part of the General Programming Boards category; When i compile the below program i get two errors stating the following: Thanks in advance for your help. I ...

  1. #1
    Registered User
    Join Date
    Apr 2006
    Posts
    51

    need help with rock paper scissors program

    When i compile the below program i get two errors stating the following: Thanks in advance for your help. I have no idea how to get these fixed.



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

    main.cpp(19): error C2660: 'report' : function does not take 4 arguments


    in file main.c:

    Code:
    #include "p_r_s.h"
    
    int main(void)
    {
    	int			win_cnt = 0, lose_cnt = 0, tie_cnt = 0;
    	outcome		result;
    	p_r_s		player_choice, machine_choice;
    
    	srand(time(NULL));
    	print_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:
    				print_game_status(win_cnt, lose_cnt, tie_cnt);
    				break;
    			case instructions:
    				print_instructions();
    				break;
    			case help:
    				print_help();
    				break;
    			default:
    				printf("PROGRAMMER ERROR: Cannot get to here!\n\n");
    				exit(1);
    		}
    	print_game_status(win_cnt, lose_cnt, tie_cnt);
    	print_final_status(win_cnt, lose_cnt);
    	return 0;
    }

    in file p_r_s.h:

    Code:
    /*The game of paper, rock, and 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_s {paper, rock, scissors,
    game, help, instructions, quit};
    
    enum outcome {win, lose, tie, error};
    
    typedef		enum p_r_s		p_r_s;
    typedef		enum outcome	outcome;
    
    outcome		compare(p_r_s player_choice, p_r_s machine_choice);
    void		print_final_status(int win_cnt, int lose_cnt);
    void		print_game_status(int win_cnt,
    							  int lose_cnt, int tie_cnt);
    
    void		print_help(void);
    void		print_instructions(void);
    void		report(outcome result, int *win_cnt_ptr,
    				int *lose_cnt_ptr, int *tie_cnt_ptr, 
    				p_r_s player_choice, p_r_s machine_choice);
    
    p_r_s		selection_by_machine(void);
    p_r_s		selection_by_player(void);
    in file print.c:

    Code:
    #include "p_r_s.h"
    
    void print_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 print_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 print_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 print_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 player and the machine will choose one\n"
    		"of p, r, or s. If the two chcices are the same,\n"
    		"then the game is a tie. Otherwise:\n"
    		"\n"
    		"	\"paper covers the rock\"		(a win for paper)\n"
    		"	\"rock breaks the scissors\"	(a win for rock)\n"
    		"	\"scissors cut the paper\"		(a win for scissors)\n"
    		"\n"
    		"There are other allowable inputs:\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");
    }
    in file select.c:
    Code:
    #include "p_r_s.h"
    
    p_r_s selection_by_machine(void)
    {
    	return ((p_r_s) (rand() % 3));
    }
    
    p_r_s selection_by_player(void)
    {
    	char	c;
    	p_r_s	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;
    }
    in file compare.c:
    Code:
    #include "p_r_s.h"
    
    outcome compare(p_r_s player_choice, p_r_s 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("PROGRAMMER ERROR: Unexpected choice!\n\n");
    		exit(1);
    	}
    	return result;
    }
    in file report.c:

    Code:
    #include "p_r_s.h"
    
    void report(outcome result, int *win_cnt_ptr,
    			int *lose_cnt_ptr, int *tie_cnt_ptr,
    			p_r_s player_choice, p_r_s machine_choice)
    {
    	static const char *text[] = { "paper", "rock", "scissors" };
    	printf("player chose %s, machine choose %s : You ",
            text[player_choice], text[machine_choice]);
    	switch (result) 
    	{
    	case win:
    		++*win_cnt_ptr;
    		puts("win.");
    		break;
    	case lose:
    		++*lose_cnt_ptr;
    		puts("lose.");
    		break;
    	case tie:
    		++*tie_cnt_ptr;
    		puts("tie.");
    		break;
    	default:
    		printf("PRGORAMMER ERROR: Unexpected result!\n\n");
    		exit(1);
    	}
    }

  2. #2
    ZuK
    ZuK is offline
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    About the warning: it looks like time_t is not an unsigned int on your system. this is not a problem for the seed value of srand() just cast to get rid of the warning
    Code:
    srand((unsigned int)time(NULL));
    There is not much to say about the error, the compiler already tells you.
    you have declared report to take 6 parameters but you call it with only 4.
    Kurt

  3. #3
    Registered User
    Join Date
    Apr 2006
    Posts
    51
    Zuk , i dont understand where do i call out 6 parameters for report. I am new to this programming game. please advise

  4. #4
    ZuK
    ZuK is offline
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    The declaration with 6 pars.
    Code:
    void		report(outcome result, int *win_cnt_ptr,
    				int *lose_cnt_ptr, int *tie_cnt_ptr, 
    				p_r_s player_choice, p_r_s machine_choice);
    your call in main
    Code:
    			case scissors:
    				machine_choice = selection_by_machine();
    				result = compare(player_choice, machine_choice);
    				report(result, &win_cnt, &lose_cnt, &tie_cnt);  // 4 pars
    				break;
    Kurt

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. BOOKKEEPING PROGRAM, need help!
    By yabud in forum C Programming
    Replies: 3
    Last Post: 11-16-2006, 10:17 PM
  2. Can someome help me with a program please?
    By WinterInChicago in forum C++ Programming
    Replies: 3
    Last Post: 09-21-2006, 10:58 PM
  3. Replies: 5
    Last Post: 09-03-2001, 09:45 PM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21