Hi here is my problem I want to have the outcome of my rock paper scissors game to print outcomes like: You chose paper and I chose rock. You win. The value for player_choice and machine_choice is declared in select.cpp (listed below).
My question is how would I go about telling, the report.cpp code below to check the select.cpp code for the variable to print?
#include "p_r_s.h"
void report(outcome result, int *win_cnt_ptr,
int *lose_cnt_ptr, int *tie_cnt_ptr)
{
switch(result) {
case win:
++*win_cnt_ptr;
printf("%27s I chose");
printf("%c", player_choice);
printf("%27s you chose");
printf("%c", machine_choice);
printf("%27s You win.\n", "\"");
break;
case lose:
++*lose_cnt_ptr;
printf("%27s i chose");
printf("%c", player_choice);
printf("%27s you chose");
printf("%c", machine_choice);
printf("%27s You lose.\n", "");
break;
case tie:
++*tie_cnt_ptr;
printf("%27s A tie.\n", "");
break;
default:
printf("PROGRAMMER ERROR: Unexpected result!\n\n");
exit(1);
}
}
#include "p_r_s.h"
p_r_s selection_by_machine(void)
{
return ((p_r_s) (rand() % 3));
}
p_r_s selection_by_player(char x)
{
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;
}