473,746 Members | 2,513 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

rock, paper, scissor help C programming

19 New Member
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:
printf("%27s I chose");
printf("%c", player_choice);
printf("%27s you chose");
printf("%c", machine_choice) ;
printf("%27s You win.\n", "\"");
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", "");
case tie:
printf("%27s A tie.\n", "");
printf("PROGRAM MER ERROR: Unexpected result!\n\n");

#include "p_r_s.h"

p_r_s selection_by_ma chine(void)
return ((p_r_s) (rand() % 3));
p_r_s selection_by_pl ayer(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;
case 'r':
player_choice = rock;
case 's':
player_choice = scissors;
case 'g':
player_choice = game;
case 'i':
player_choice = instructions;
case 'q':
player_choice = quit;
player_choice = help;
return player_choice;
Sep 2 '08 #1
8 5462
1,275 Recognized Expert Top Contributor
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 ...

Sep 2 '08 #2
19 New Member
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
1,275 Recognized Expert Top Contributor
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.

Sep 2 '08 #4
11,448 Recognized Expert MVP
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,

Sep 2 '08 #5
9,208 Recognized Expert Moderator Expert
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;
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;
The linker will hook the variable in one file to the code in the other file.
Sep 2 '08 #6
19 New Member
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"
  3. outcome compare(p_r_s player_choice, p_r_s machine_choice)
  4. {
  5.     outcome result;
  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. }
Sep 4 '08 #7
19 New Member
Whoops I just figured it out but thanks to everyone that responded and tried to help
Sep 4 '08 #8
9,208 Recognized Expert Moderator Expert
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

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 http://journyx.com/clf
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 know something must be different on the machines. But what? I have checked everything ! Thanks, Ira
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 scrolling-preview, but with page breaks and page numbering appropriate to the paper size. I have a sense that this can be done in xsl, since xsl defines the format for everything else in the report. My goal is to avoid the time and expense of...
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 players choice, and rock is the computers choice, for reference i was given the p_r_s.h, compare.c, main.c, selection.c, and wrt.c, and i have had to build the report.c to describe the
by: Piotr Nienaltowski | last post by:
!!! DEADLINE FOR PAPER SUBMISSIONS HAS BEEN EXTENDED UNTIL FEBRUARY 26, 2004 !!! ---------------------------------------------------------------- .NET TECHNOLOGIES 2004 2nd International Workshop on .NET Technologies University of West Bohemia Pilsen (Czech Republic) May 31 - June 2, 2004
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 figure out this? I am using following code: Dim customPaperSize As New PaperSize("11x9", 1100, 900) pdMain.DefaultPageSettings.PaperSize = customPaperSize
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 rand() and srand() */ #include <time.h> /* for time() */ /*User Inputs R,P,S,Q*/
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 of what i want Rock beats Scissor Paper beats rock Scissor beats paper msgbox 'Enter your choce' If txta.text = "Rock" then
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 load up with the program? I am using JCreator for this project. I have created the Basic Java Application project, and then added in the 3 .java files that I need to run the program, but I just can not figure out how or where I need to upload the...
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.