Welcome to Dream.In.Code
Become a C++ Expert!

Join 149,473 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,897 people online right now. Registration is fast and FREE... Join Now!




Rock Paper Scissors Program

 
Reply to this topicStart new topic

Rock Paper Scissors Program

trbl
27 Jan, 2008 - 05:02 PM
Post #1

New D.I.C Head
*

Joined: 26 Jan, 2008
Posts: 20

I have gotten to this point with my Program for Rock Paper, Scissors but when I run it it will not play and only continue to give me options if usable keys for the game. I am stumped. Could someone please point me in the right direction. I have posted the program below:

CODE
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

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_chioce, p_r_s 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);
p_r_s selection_by_machine(void);
p_r_s selection_by_player(void);



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 chose 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 breaks the scissors\"   (a win for rock)\n"
            "   \"scissors cut the paper\"   (a win for scissors)\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");
    }

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 © {
            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;
    }


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));
    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("PROGRAMMER 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;
}


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   qiut this game\n");
}

    

    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;
    }


    
    void report(outcome result, int *win_cnt_ptr, int *lose_cnt_ptr, int
*tie_cnt_ptr)

{
switch (result) {
p_r_s    player_choice, machine_choice;
case win:
++*win_cnt_ptr;
if (player_choice == paper)
printf("%35sYou chose paper and I chose rock. You win.\n", "");
else if (player_choice == rock)
printf("%35sYou chose rock and I chose scissors. You win.\n", "");
else if (player_choice == scissors)
printf("%35sYou chose scissors and  I chose paper. You win.\n", "");
break;
case lose:
++*lose_cnt_ptr;
if (player_choice == paper)
printf("%35sYou chose paper and I chose scissors. You lose.\n", "");
else if (player_choice == rock)
printf("%35sYou chose rock and I chose paper. You lose.\n", "");
else if (player_choice == scissors)
printf("%35sYou chose scissors and I chose rock. You lose.\n", "");
break;
case tie:
++*tie_cnt_ptr;
if (player_choice == paper)
printf("%35sYou chose paper and I chose paper. We tie.\n", "");
else if (player_choice == rock)
printf("%35sYou chose rock and I chose rock. We tie.\n", "");
else if (player_choice == scissors)
printf("%35sYou chose scissors and I chose scissors. We tie.\n", "");
break;
default:
printf("PROGRAMMER ERROR: Unexpected result!\n\n");
exit(1);

}
}


Thank you for any guidance you can throw my way.


*mod edit - added code tags
User is offlineProfile CardPM
+Quote Post

Tom9729
RE: Rock Paper Scissors Program
27 Jan, 2008 - 06:15 PM
Post #2

Debian guru
Group Icon

Joined: 30 Dec, 2007
Posts: 1,582



Thanked: 12 times
Dream Kudos: 325
My Contributions
Please post your code inside code tags. code.gif

One thing I noticed right off the bat is that you're trying to switch on a copyright sign?

This post has been edited by Tom9729: 27 Jan, 2008 - 06:17 PM
User is online!Profile CardPM
+Quote Post

GWatt
RE: Rock Paper Scissors Program
27 Jan, 2008 - 06:49 PM
Post #3

human inside
Group Icon

Joined: 1 Dec, 2005
Posts: 2,356



Thanked: 31 times
Dream Kudos: 500
My Contributions
No, he's not doing that. On DIC, when you write ( c ) without the spaces between, it replaces that with ©.

OK, for whatever the reason, the computer is reading in the linefeed character when you hit enter.

you can use the getc() function and pass stdin as the argument.
char c = getc(stdin);

You might have to use getc() twice to move past the newline character.
User is offlineProfile CardPM
+Quote Post

trbl
RE: Rock Paper Scissors Program
28 Jan, 2008 - 12:37 PM
Post #4

New D.I.C Head
*

Joined: 26 Jan, 2008
Posts: 20

QUOTE(GWatt @ 27 Jan, 2008 - 07:49 PM) *

No, he's not doing that. On DIC, when you write ( c ) without the spaces between, it replaces that with ©.

OK, for whatever the reason, the computer is reading in the linefeed character when you hit enter.

you can use the getc() function and pass stdin as the argument.
char c = getc(stdin);

You might have to use getc() twice to move past the newline character.



In am really a begginer so when I get to my text I will look up your suggestion. Unfortunately this text is horrible an explains very little or I would have an easier time. If you have any further suggestions I would greatly appreciate it.
User is offlineProfile CardPM
+Quote Post

fvillarr
RE: Rock Paper Scissors Program
8 Jul, 2008 - 05:30 PM
Post #5

New D.I.C Head
*

Joined: 8 Jul, 2008
Posts: 2

QUOTE(trbl @ 27 Jan, 2008 - 06:02 PM) *

I have gotten to this point with my Program for Rock Paper, Scissors but when I run it it will not play and only continue to give me options if usable keys for the game. I am stumped. Could someone please point me in the right direction. I have posted the program below:

CODE
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

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_chioce, p_r_s 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);
p_r_s selection_by_machine(void);
p_r_s selection_by_player(void);



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 chose 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 breaks the scissors\"   (a win for rock)\n"
            "   \"scissors cut the paper\"   (a win for scissors)\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");
    }

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 © {
            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;
    }


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));
    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("PROGRAMMER 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;
}


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   qiut this game\n");
}

    

    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;
    }


    
    void report(outcome result, int *win_cnt_ptr, int *lose_cnt_ptr, int
*tie_cnt_ptr)

{
switch (result) {
p_r_s    player_choice, machine_choice;
case win:
++*win_cnt_ptr;
if (player_choice == paper)
printf("%35sYou chose paper and I chose rock. You win.\n", "");
else if (player_choice == rock)
printf("%35sYou chose rock and I chose scissors. You win.\n", "");
else if (player_choice == scissors)
printf("%35sYou chose scissors and  I chose paper. You win.\n", "");
break;
case lose:
++*lose_cnt_ptr;
if (player_choice == paper)
printf("%35sYou chose paper and I chose scissors. You lose.\n", "");
else if (player_choice == rock)
printf("%35sYou chose rock and I chose paper. You lose.\n", "");
else if (player_choice == scissors)
printf("%35sYou chose scissors and I chose rock. You lose.\n", "");
break;
case tie:
++*tie_cnt_ptr;
if (player_choice == paper)
printf("%35sYou chose paper and I chose paper. We tie.\n", "");
else if (player_choice == rock)
printf("%35sYou chose rock and I chose rock. We tie.\n", "");
else if (player_choice == scissors)
printf("%35sYou chose scissors and I chose scissors. We tie.\n", "");
break;
default:
printf("PROGRAMMER ERROR: Unexpected result!\n\n");
exit(1);

}
}


Thank you for any guidance you can throw my way.


*mod edit - added code tags

To the best of my knowledge here is the corrected program it works well.
I commented some of the major changes. For the rest, compare the two programs.
CODE

#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>


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;

void prn_instructions(void);
p_r_s selection_by_player(void);
p_r_s selection_by_machine(void);

/* u misspelled choice in player_choice for the */
/* outcome function*/

outcome compare(p_r_s player_choice, p_r_s machine_choice);
void report(outcome result, p_r_s player_choice,
            int *win_cnt_ptr, int *lose_cnt_ptr, int *tie_cnt_ptr);
void prn_help(void);
void prn_final_status(int win_cnt, int lose_cnt);
void prn_game_status(int win_cnt, int lose_cnt, int tie_cnt);


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));
    prn_instructions();
        
        do
        {    
             player_choice = selection_by_player();
             machine_choice = selection_by_machine();
            
        switch (player_choice){
            case paper:              
            case rock:
            case scissors:
                result = compare(player_choice, machine_choice);
                report(result, player_choice, &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;
            case quit:
                break;
            default:
                printf("PROGRAMMER ERROR: Cannot get to here!\n\n");
                exit(1);
            }
            
        } while (player_choice != quit);
    
    prn_game_status(win_cnt, lose_cnt, tie_cnt);
    prn_final_status(win_cnt, lose_cnt);
    printf("Type any letter then hit the enter key\n");
    scanf("%");
    
    return 0;
}
void prn_instructions(void)
    {
        printf("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 chose 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 breaks the scissors\"   (a win for rock)\n"
               "   \"scissors cut the paper\"   (a win for scissors)\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");
    }

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: ");

/* \t corrects some problems in reading the char c repeated times*/        
    
             scanf("\t%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;
/* Here u forgot the case for quit */
            case 'q':
                player_choice = quit;
                break;
            default:
                player_choice = help;
                break;
        }
      
       return player_choice;
    }


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("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");
}

    

    outcome compare(p_r_s player_choice, p_r_s machine_choice)
{
        outcome result;

        if(player_choice == machine_choice)
                result = 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;
  }

  void report(outcome result, p_r_s player_choice,
              int *win_cnt_ptr, int *lose_cnt_ptr, int *tie_cnt_ptr)

{
switch (result)
            
            {
/* p_r_s    player_choice, machine_choice; */
/* don't redefine player and machine choice they will  */
/* reset to garbage*/    
            case win:
                 ++*win_cnt_ptr;
              if (player_choice == paper)
                 printf("You chose paper and I chose rock. You win.\n");
              else if (player_choice == rock)
                 printf("You chose rock and I chose scissors. You win.\n");
              else if (player_choice == scissors)
                 printf("You chose scissors and  I chose paper. You win.\n");
                 break;
            case lose:
                 ++*lose_cnt_ptr;
              if (player_choice == paper)
                 printf("You chose paper and I chose scissors. You lose.\n");
              else if (player_choice == rock)
                 printf("You chose rock and I chose paper. You lose.\n");
              else if (player_choice == scissors)
                 printf("You chose scissors and I chose rock. You lose.\n");
                 break;
            case tie:
                 ++*tie_cnt_ptr;
              if (player_choice == paper)
                 printf("You chose paper and I chose paper. We tie.\n");
              else if (player_choice == rock)
                 printf("You chose rock and I chose rock. We tie.\n");
              else if (player_choice == scissors)
                 printf("You chose scissors and I chose scissors. We tie.\n");
                 break;
            default:
                 printf("PROGRAMMER ERROR: Unexpected result!\n\n");
                 exit(1);
            }
}


** Edit ** code.gif
User is offlineProfile CardPM
+Quote Post

</
fvillarr
RE: Rock Paper Scissors Program
8 Jul, 2008 - 05:44 PM
Post #6

New D.I.C Head
*

Joined: 8 Jul, 2008
Posts: 2

here is the corrected code.

CODE

#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>


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;

void prn_instructions(void);
p_r_s selection_by_player(void);
p_r_s selection_by_machine(void);

/* you misspelled choice in player_choice for the */
/* outcome function */

outcome compare(p_r_s player_choice, p_r_s machine_choice);
void report(outcome result, p_r_s player_choice,
            int *win_cnt_ptr, int *lose_cnt_ptr, int *tie_cnt_ptr);
void prn_help(void);
void prn_final_status(int win_cnt, int lose_cnt);
void prn_game_status(int win_cnt, int lose_cnt, int tie_cnt);


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));
    prn_instructions();
        
/* I did a different loop compare the two*/  
      do
        {    
             player_choice = selection_by_player();
             machine_choice = selection_by_machine();
            
        switch (player_choice){
            case paper:              
            case rock:
            case scissors:
                result = compare(player_choice, machine_choice);
                report(result, player_choice, &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;
           case quit:
                break;
            default:
                printf("PROGRAMMER ERROR: Cannot get to here!\n\n");
                exit(1);
            }
            
        } while (player_choice != quit);
    
    prn_game_status(win_cnt, lose_cnt, tie_cnt);
    prn_final_status(win_cnt, lose_cnt);

/* the following holds the output if using the gnu compiler

    printf("Type any letter then hit the enter key\n");
    scanf("%");
    
    return 0;
}
void prn_instructions(void)
    {
        printf("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 chose 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 breaks the scissors\"   (a win for rock)\n"
               "   \"scissors cut the paper\"   (a win for scissors)\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");
    }

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: ");
/* \t solves some problems with reading the char c  after the  */
/* first time in the loop */            
             scanf("\t%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;
/* I think you forgot the case for quit here*/
           case 'q':
                player_choice = quit;
                break;
            default:
                player_choice = help;
                break;
        }
      
       return player_choice;
    }


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("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");
}

    

    outcome compare(p_r_s player_choice, p_r_s machine_choice)
{
        outcome result;

        if(player_choice == machine_choice)
                result = 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;
  }

  void report(outcome result, p_r_s player_choice,
              int *win_cnt_ptr, int *lose_cnt_ptr, int *tie_cnt_ptr)

{

/*no need the redefine player and machine choice here */
/* if you do you will put garbage in those variables.*/
/* you need p_r_s player_choice not just outcome result */
/* in the function. */

switch (result)
            
            {
            
            case win:
                 ++*win_cnt_ptr;
              if (player_choice == paper)
                 printf("You chose paper and I chose rock. You win.\n");
              else if (player_choice == rock)
                 printf("You chose rock and I chose scissors. You win.\n");
              else if (player_choice == scissors)
                 printf("You chose scissors and  I chose paper. You win.\n");
                 break;
            case lose:
                 ++*lose_cnt_ptr;
              if (player_choice == paper)
                 printf("You chose paper and I chose scissors. You lose.\n");
              else if (player_choice == rock)
                 printf("You chose rock and I chose paper. You lose.\n");
              else if (player_choice == scissors)
                 printf("You chose scissors and I chose rock. You lose.\n");
                 break;
            case tie:
                 ++*tie_cnt_ptr;
              if (player_choice == paper)
                 printf("You chose paper and I chose paper. We tie.\n");
              else if (player_choice == rock)
                 printf("You chose rock and I chose rock. We tie.\n");
              else if (player_choice == scissors)
                 printf("You chose scissors and I chose scissors. We tie.\n");
                 break;
            default:
                 printf("PROGRAMMER ERROR: Unexpected result!\n\n");
                 exit(1);
            }
}


** Edit ** -----> code.gif <-----
User is offlineProfile CardPM
+Quote Post