473,320 Members | 1,961 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

rock, paper, scissor help C programming

19
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;
}
Sep 2 '08 #1
8 5425
gpraghuram
1,275 Expert 1GB
R u saking how should you call the corresponding function in select.cpp or something else..?
can you explain it further as ia m not able to understand ...

Raghu
Sep 2 '08 #2
jmf777
19
yeah thats basically it. In select.cpp the player and the machine makes a choice of rock paper or scissor. In report.cpp I want to call the selection that the player and the machine made in select.cpp to report.cpp and print that selection.
Sep 2 '08 #3
gpraghuram
1,275 Expert 1GB
yeah thats basically it. In select.cpp the player and the machine makes a choice of rock paper or scissor. In report.cpp I want to call the selection that the player and the machine made in select.cpp to report.cpp and print that selection.

I think you have to call the report() function in a loop and from the report function you have to call the function in select().


NOTE:Please use code tags while posting the code.


Raghu
Sep 2 '08 #4
JosAH
11,448 Expert 8TB
Expand|Select|Wrap|Line Numbers
  1.     printf("%27s I chose");
You do that all over the place; check your manuals because it is not correct.

kind regards,

Jos
Sep 2 '08 #5
weaknessforcats
9,208 Expert Mod 8TB
You use a storage class specifier to tell the compiler the variable exists but it's not in this file:

Expand|Select|Wrap|Line Numbers
  1. /*report.cpp*/
  2. extern p_r_s player_choice;
  3. extern p_r_s machine_choice;
  4.  
Then just define the variables in another file:
Expand|Select|Wrap|Line Numbers
  1. /*select.cpp*/
  2. p_r_s player_choice;
  3. p_r_s machine_choice;
  4.  
The linker will hook the variable in one file to the code in the other file.
Sep 2 '08 #6
jmf777
19
I've got the program to at least build and executed it by adding the underlined code.

Expand|Select|Wrap|Line Numbers
  1. void report(outcome result, int *win_cnt_ptr,
  2.             int *lose_cnt_ptr, int *tie_cnt_ptr, p_r_s player_choice, p_r_s machine_choice)
to my header and my report function but now when I win. It prints funny characters like an up and down character before "you chose" and a smiley face box after "you chose." I'm now lost can someone please point me in the right direction. I'm assuming its because my outcome function is only returning a win or lose to main.

Expand|Select|Wrap|Line Numbers
  1. #include "p_r_s.h"
  2.  
  3. outcome compare(p_r_s player_choice, p_r_s machine_choice)
  4. {
  5.     outcome result;
  6.  
  7.     if (player_choice == machine_choice)
  8.         return tie;
  9.     switch (player_choice) {
  10. case paper:
  11.     result = (machine_choice == rock) ? win : lose;
  12.     break;
  13. case rock:
  14.     result = (machine_choice == scissors) ? win : lose;
  15.     break;
  16. case scissors:
  17.     result = (machine_choice == paper) ? win : lose;
  18.     break;
  19. default:
  20.     printf("PROGRAMMER ERROR: Unexpected choice!\n\n");
  21.     exit(1);
  22.     }
  23.     return result;
  24. }
  25.  
Sep 4 '08 #7
jmf777
19
Whoops I just figured it out but thanks to everyone that responded and tried to help
Sep 4 '08 #8
weaknessforcats
9,208 Expert Mod 8TB
Whoops I just figured it out
That's what we like to see.
Sep 4 '08 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: ccdetail | last post by:
http://www.journyx.com/pdf/PythonAtAGlance.pdf the above paper is a response to some of our prospects complaints they were asking us why we use python thought you guys might be interested ...
5
by: Ira S | last post by:
I use a DYMO labelwriter with my Access 97 database. I just purchased a new computer and in the report section under page setup/paper size, the new computer keeps changing the size automatically. I...
5
by: bcanavan | last post by:
When I export xml(and xls) from Access 2003 the result is a complete report in a single page. I would like to get the entire report in a single page (one trip to the server) for printing and...
7
by: TooNaive | last post by:
Hello all, I'm taking a C class and am having to write a program to play a game of rock, paper scissors, and with the output of: You chose paper and I chose rock. You Win where paper is the...
0
by: Piotr Nienaltowski | last post by:
!!! DEADLINE FOR PAPER SUBMISSIONS HAS BEEN EXTENDED UNTIL FEBRUARY 26, 2004 !!! ---------------------------------------------------------------- .NET TECHNOLOGIES 2004 2nd International...
4
by: Sukh | last post by:
Hi, I am tring to change the paper size from default to custom paper size. In print preview its showing my custom size but when I print it print on default paper size. Can any one help me to...
12
by: gc | last post by:
Hi I'm working on a rock, scissors, paper program. I think I have most of it, but I am having trouble with my main function, here is my code: #include <stdio.h> #include <stdlib.h> /* for...
11
by: blackhacker | last post by:
Please can anyone help me to make a simple simple Java code to force the game scissor,paper,rock to work ? for example i know how to do it in Visual Basic but not in java,for example this is kind...
1
by: flg22 | last post by:
Hi I am working on this Rock, paper, scissors java game and the program works, but I can not figure out how to get the images to load onto the program. So my question is how do I get the images to...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.