473,698 Members | 1,877 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Building Paper, Rock, Scissors

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
output. I will post what i have so far in this venture, but when i
compile i keep getting 2 fatal errors and i cannot figure out what to
do next. Any help would be greatly appreciated. The files are as
follows:

the report.c file that i am working on is this:

report.c file
#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)

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

}
}

_______________ _______________ _______________ _______________ _______________ __

the
p_r_s.h file:

/* The game of paper, rock, 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 wrt_final_statu s(int win_cnt, int lose_cnt);
void wrt_game_status (int win_cnt, int lose_cnt, int tie_cnt);
void wrt_help(void);
void wrt_instruction s(void);
void report_and_tabu late(outcome result,
int *win_cnt_ptr, int *lose_cnt_ptr, int *tie_cnt_ptr);
p_r_s selection_by_ma chine(void);
p_r_s selection_by_pl ayer(void);

_______________ _______________ _______________ _______________ _______________ _

the
compare.c file:

#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("\nPROGR AMMER ERROR: Unexpected choice!\n\n");
exit(1);
}
return result;
}

_______________ _______________ _______________ _______________ _____________

the
main.c file:

#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 )); /* seed the random number generator
*/
wrt_instruction s();
while ((player_choice = selection_by_pl ayer()) != quit)
switch (player_choice) {
case paper:
case rock:
case scissors:
machine_choice = selection_by_ma chine();
result = compare(player_ choice, machine_choice) ;
report_and_tabu late(result, &win_cnt, &lose_cnt, &tie_cnt);
break;
case game:
wrt_game_status (win_cnt, lose_cnt, tie_cnt);
break;
case instructions:
wrt_instruction s();
break;
case help:
wrt_help();
break;
default:
printf("\nPROGR AMMER ERROR: Cannot get to here!\n\n");
exit(1);
}
wrt_game_status (win_cnt, lose_cnt, tie_cnt);
wrt_final_statu s(win_cnt, lose_cnt);
return 0;
}

_______________ _______________ _______________ _______________ _______________ _

the
selection.c file:

#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(void)
{
char c;
p_r_s player_choice;

printf("Input p, r, or s: ");
while (isspace((int) (c = getchar()))) /* skip white space
*/
;
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;
}

_______________ _______________ _______________ _______________ _____________

and the wrt.c file:

#include "p_r_s.h"

void wrt_final_statu s(int win_cnt, int lose_cnt)
{
if (win_cnt > lose_cnt)
printf("CONGRAT ULATIONS - 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 wrt_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 wrt_help(void)
{
printf("\n%s\n" ,
"---\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 wrt_instruction s(void)
{
printf("\n%s\n" ,
"---\n"
"PAPER, ROCK, SCISSORS:\n"
" In this game p is for \"paper,\" r is for \"rock,\" and"
" s is for \"scissors.\"\n "
" Both the player and the machine\n"
" will choose one of p, r, or s."
" If the two choices are the same,\n"
" then the game is a tie. Otherwise:\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 (the number of wins so far),\n"
" h for help,\n"
" i for instructions (reprint these instructions),\ n"
" q for quit (to quit the game).\n"
"\n"
" This game is played repeatedly until q is entered.\n"
"\n"
" Good luck!\n");
}


Thanks in advance for any help!
Nov 14 '05 #1
7 3802
TooNaive wrote:

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)
This is the function you wrote, ...
void report_and_tabu late(outcome result,
int *win_cnt_ptr, int *lose_cnt_ptr, int *tie_cnt_ptr);


.... but this is the function the rest of the code expects.

The function you wrote is never called, and the one that is
called does not exist.

Nov 14 '05 #2
Thanks T.M. for your help, but i am still getting an error when i
compile. I am using Microsoft Visual Studio.net and whenever i compile
i get this error:

report.cpp(5) : error C2447: '{' : missing function header (old-style
formal list?)

the line it references is this one:

1.#include "p_r_s.h"
2.
3.void report_and_tabu late(outcome result, int *win_cnt_ptr, int
4.*lose_cnt_ptr , int *tie_cnt_ptr);
5."This line here"
6. {
7. switch (result) {

I have tried adding more {'s, taking away {'s and even went and
re-studied the entire definition of "function headers" and have still
drawn a blank. Could it be my compiler? I know microsoft just loves
adding little bugs in all their software. Any suggestions would be
greatly appreciated. Thanks again!
Nov 14 '05 #3
TooNaive wrote:
Thanks T.M. for your help, but i am still getting an error when i
compile. I am using Microsoft Visual Studio.net and whenever i compile
i get this error:

report.cpp(5) : error C2447: '{' : missing function header (old-style
formal list?)

the line it references is this one:

1.#include "p_r_s.h"
2.
3.void report_and_tabu late(outcome result, int *win_cnt_ptr, int
4.*lose_cnt_ptr , int *tie_cnt_ptr);
5."This line here"
6. {
7. switch (result) {

I have tried adding more {'s, taking away {'s and even went and
re-studied the entire definition of "function headers" and have still
drawn a blank. Could it be my compiler? I know microsoft just loves
adding little bugs in all their software. Any suggestions would be
greatly appreciated. Thanks again!


Try the usual technique: strip away as much code as possible, ending
up with a very small program that stil has this problem. There's a
good chance you'll find what's wrong in the process. If not, post
the few lines you've left here.

HTH

Case

Nov 14 '05 #4
TooNaive wrote:
Thanks T.M. for your help, but i am still getting an error when i
compile. I am using Microsoft Visual Studio.net and whenever i compile
i get this error:

report.cpp(5) : error C2447: '{' : missing function header (old-style
formal list?)

the line it references is this one:

1.#include "p_r_s.h"
2.
3.void report_and_tabu late(outcome result, int *win_cnt_ptr, int
4.*lose_cnt_ptr , int *tie_cnt_ptr);
5."This line here"
6. {
7. switch (result) {

I have tried adding more {'s, taking away {'s and even went and
re-studied the entire definition of "function headers" and have still
drawn a blank. Could it be my compiler? I know microsoft just loves
adding little bugs in all their software. Any suggestions would be
greatly appreciated. Thanks again!


It said "report.cpp(5)" ...
(try making a file named "report.c")
--
Song

/* E-mail.c */
#define User "Y.Song"
#define Warwick "dcs.warwick.ac .uk"
int main() {
printf("Yu Song's E-mail: %s@%s", User, Warwick);
return 0;}

Further Info. : http://www.dcs.warwick.ac.uk/~esubbn/
_______________ _______________ _______________ __________

Nov 14 '05 #5
Try removing the ; at the end of line 4, with this it is a function
prototype and the body is not part of it.

"TooNaive" <ni*****@yahoo. com> wrote in message
news:34******** *************** ***@posting.goo gle.com...
Thanks T.M. for your help, but i am still getting an error when i
compile. I am using Microsoft Visual Studio.net and whenever i compile
i get this error:

report.cpp(5) : error C2447: '{' : missing function header (old-style
formal list?)

the line it references is this one:

1.#include "p_r_s.h"
2.
3.void report_and_tabu late(outcome result, int *win_cnt_ptr, int
4.*lose_cnt_ptr , int *tie_cnt_ptr);
5."This line here"
6. {
7. switch (result) {

I have tried adding more {'s, taking away {'s and even went and
re-studied the entire definition of "function headers" and have still
drawn a blank. Could it be my compiler? I know microsoft just loves
adding little bugs in all their software. Any suggestions would be
greatly appreciated. Thanks again!

Nov 14 '05 #6
TooNaive wrote:
Thanks T.M. for your help, but i am still getting an error when i
compile. I am using Microsoft Visual Studio.net and whenever i compile
i get this error:

report.cpp(5) : error C2447: '{' : missing function header (old-style
formal list?)

the line it references is this one:

1.#include "p_r_s.h"
2.
3.void report_and_tabu late(outcome result, int *win_cnt_ptr, int
4.*lose_cnt_ptr , int *tie_cnt_ptr); ^^^
What is this semicolon doing here?
5."This line here" ^^^^^^^^^^^^^^^ ^
And why is this line outside the braces of the function body?
6. {
7. switch (result) {

I have tried adding more {'s, taking away {'s and even went and
re-studied the entire definition of "function headers" and have still
drawn a blank. Could it be my compiler? I know microsoft just loves
adding little bugs in all their software.
It looks like you have inserted two massive bugs into your software.
Any suggestions would be
greatly appreciated. Thanks again!

Nov 14 '05 #7
TooNaive wrote:
Thanks T.M. for your help, but i am still getting an error when i
compile. I am using Microsoft Visual Studio.net and whenever i compile
i get this error:

report.cpp(5) : error C2447: '{' : missing function header (old-style
formal list?)

the line it references is this one:

1.#include "p_r_s.h"
2.
3.void report_and_tabu late(outcome result, int *win_cnt_ptr, int
4.*lose_cnt_ptr , int *tie_cnt_ptr);


Get rid of the semi-colon at the end.
--
Thomas M. Sommers -- tm*@nj.net -- AB2SB

Nov 14 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1393
by: Jeff Epler | last post by:
I tried building the documentation with "make pdf", and got a long list of warnings on "lib" (hbox, vbox, and reference warnings), ending with a TeX error: LaTeX Warning: Reference `module-cookielib' on page 512 undefined on input line 73. ) (/usr/src/cvs-src/python/dist/src/Doc/lib/libxmlrpclib.tex Overfull \vbox (118.57pt too high) has occurred while \output is active Overfull \hbox (66.62143pt too wide) in paragraph at lines 56--69
12
2221
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*/
6
2651
by: Bob Alston | last post by:
Looking for someone with experience building apps with multiple instances of forms open. I am building an app for a nonprofit organizations case workers. They provide services to the elderly. so far I have built a traditional app, switchboard, forms, etc. Part of this app is to automate the forms they previously prepared manually. After the app was built and works just fine, I find out there are several case managers using MS word...
11
2418
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
1
3112
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...
8
5459
by: jmf777 | last post by:
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...
2
2525
by: Izkimar | last post by:
I'm supposed to redesign this paper scissors rock game that first happened between 2 players, and for only one round. Yet, now I'm supposed to take for loops and ask them if they want to play against an A.I., or against just another player, or another player and an A.I.. Also, I am supposed to ask them how many rounds they want to play using the for loop. This is the jumble of mess I started, and I haven't been able to work around it so far.....
0
1360
by: Drew Riegler | last post by:
I am building an app that requires printing of multiple paper forms for each record in a csv text file (could easily be MS Access or mySQL table rows). Each row in the csv file represents a patient being admitted for a surgical procedure. For each patient, I need to print 18 different paper forms which comprise that patient's "chart". Each paper form needs to be pre-populated with some data from the input file (e.g, name, age, etc.) before...
0
8600
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,...
0
9018
jinu1996
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...
1
8890
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8858
tracyyun
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...
0
4360
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4614
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3038
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
2
2322
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1997
bsmnconsultancy
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.