I'm Stuck. And Confused

I'm in an intro to c++ class and I am stuck on my current lab. The assignment is to make a rock, paper scissor game described below.

****************************************************************************************************************************************************************

The purpose of this exercise is to give you an opportunity to practice using CinReader to handle user keyboard inputs, use branching statements to control the flow of a program, and work on your C++ programming style.

In this exercise, you will implement a rock-scissors-paper game. The computer will select rock, scissors, or paper randomly (and of course not reveal this selection to the player), the player will then enter 'R', 'S', or 'P' for her or his selection, and then the program will let the player know if she or he won. At the end of each round, allow the player to choose whether or not she or he wants to continue playing.

You must implement/include the following features in addition to the game play:

keep count of the number of times the player selects rock, scissors, and paper -- when the player chooses to stop playing, display these counts.

****************************************************************************************************************************************************************


I have included my coding I have so far below. I am having a hard time with the whole thing. Should I just start the choices as chars or do I need to initially declare them as integers. Also the switch at the bottom has nine different possible outcomes. But before I put them all down I was hoping there was an easier way to do it. Any help would be greatly appreciated. . . Also the CinReader file attached is what our teacher wants us to use to read all integers. Thanks again.

*************CODE BELOW********


#include <iostream>
#include "CinReader.h"
using namespace std;
CinReader reader;

int main()
{
cout << " ############################################" << endl;
cout << " #**** LET'S PLAY ROCK, PAPER, SCISSOR *****#" << endl;
cout << " ############################################\n" <<endl;

int rock = 0;
int paper = 0;
int scissor = 0;
int computerChoice = 0;
computerChoice = (rand()% 3)+1;
int playerChoice = 0;

cout << "Choose One of the Following:\n" << endl;
cout << " To Pick ROCK Type: R" << endl;
cout << " To Pick PAPER Type: P" << endl;
cout << " To Pick SCISSOR Type: S" << endl << endl << endl;

cout << " What is your choice?" << endl;
playerChoice = reader.readInt();

switch (computerChoice)
{
case 1:
if (playerChoice == rock) // Human Picked Rock
cout << "Draw" << endl;
else if (playerChoice == paper)
cout << "You Lose" << endl;
else if (playerChoice == scissor)
cout << "You Win" << endl;
else
cout << playerChoice << " is not an option " << endl;

break;
}

case 2:
{

if (playerChoice == rock)
cout << "You lose" << endl;
else if (playerChoice == paper)
cout << "Draw" << endl;
else if (playerChoice == scissor)
cout << "You Win" << endl;
else
cout << playerChoice << " is not an option " << endl;
break;
}

case 3:
{

if (playerChoice == rock)
cout << "You Win" << endl;
else if (playerChoice == paper)
cout << "You Lose" << endl;
else if (playerChoice == scissor)
cout << "Draw" << endl;
else
cout << playerChoice << " is not an option!!" << endl;
break;
}
}
return 0;
}
USE CODE TAGS.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <iostream>
#include "CinReader.h"
using namespace std;
CinReader reader;

int main()
{
  cout << " ############################################" << endl;
  cout << " #**** LET'S PLAY ROCK, PAPER, SCISSOR *****#" << endl;
  cout << " ############################################\n" <<endl;

  int rock = 0;
  int paper = 0;
  int scissor = 0;
  int computerChoice = 0;
  computerChoice = (rand()% 3)+1;
  int playerChoice = 0;

  cout << "Choose One of the Following:\n" << endl;
  cout << " To Pick ROCK Type: R" << endl;
  cout << " To Pick PAPER Type: P" << endl;
  cout << " To Pick SCISSOR Type: S" << endl << endl << endl;

  cout << " What is your choice?" << endl;
  playerChoice = reader.readInt();

  switch (computerChoice)
  {
    case 1:
    if (playerChoice == rock) // Human Picked Rock
      cout << "Draw" << endl;
    else if (playerChoice == paper)
      cout << "You Lose" << endl;
    else if (playerChoice == scissor)
      cout << "You Win" << endl;
    else
      cout << playerChoice << " is not an option " << endl;

    break;
  }

  case 2:
  {

    if (playerChoice == rock) 
      cout << "You lose" << endl;
    else if (playerChoice == paper)
      cout << "Draw" << endl;
    else if (playerChoice == scissor)
      cout << "You Win" << endl;
    else
      cout << playerChoice << " is not an option " << endl;
    break;
  }

  case 3:
  {

    if (playerChoice == rock)
      cout << "You Win" << endl;
    else if (playerChoice == paper)
      cout << "You Lose" << endl;
    else if (playerChoice == scissor)
      cout << "Draw" << endl;
    else
      cout << playerChoice << " is not an option!!" << endl;
    break;
  }
}
return 0;
}


Does this compile? Namely, have scope brackets that don't line up with one another and it appears your main ends prior to reaching "return 0;" Also, I would encourage you too look at the formatting structure for switch statements. http://cplusplus.com/doc/tutorial/control/

The structure is this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
int x = SOMEVALUE;
switch (x)
{
  case 1 :
    //Do Something
    //Fall through to next statement because no break
  case 2 :
    // Do Something
    //Do NOT fall through to next statement because there is a break
    break;
  case 3 :
    // Do Something
    break;
  default :
    //Do something
    break;
}


Your switch statement is closed "}" after evaluating "case 1: ".
Last edited on
Topic archived. No new replies allowed.