Chutes and Ladders Help

Hello! I'm currently a beginner to C++ programming and have ran into my first stump with a program, specifically with Chutes and Ladders. I'm completely clueless on how to approach the coding after asking for the 2 players' names. Logically, I should be prompting the user to "spin" the spinner, which I do by calling the function 'spinner'. But what I'm a bit stuck on is how to put that in a 'while' loop for each of the players' turn. Additionally, I'm also not sure how to go back and forth for each players' turn. Would I need to create a variable for each turn that are respective to the 2 players? Anyway, the code is obviously not complete but I've tried to program what I could. I'd appreciate any tips and suggestions. And also, arrays are not allowed. Thank you!

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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include <iostream>
#include <cstdlib>
using namespace std;

void welcome();
void spinner();
void checkPosition();
void checkChutesLadders();
void checkWinner();

int main()
{
  int spaceP1; //Position of player 1
  int spaceP2; // Position of player 2
  int spinMove;// Spinner that retrieves a rand num
  string player1; // Name of player 1
  string player2; // Name of player 2
  int game = 1 // Maintains the loop

  welcome();

  cout << "Enter your name (Player 1)... ";
  cin >> player1;
  cout << "Enter Player 2's name... ";
  cin >> player2;

  while (game == 1) {
    if (turn1 == player1) {
      spinner();


void welcome()
{
  cout << "Welcome to a game of Chutes and Ladders! \n";
  cout << "You and player 2 will take turns spinning the spinner. \n";
  cout << "The first person to land on 'Space 100' is the winner! \n";
  cout << "However, there are chutes and ladders on the board that \n";
  cout << "will either expedite or delay your destination to space 100 \n";
  cout << "Time to play!";
}

int spinner()
{
  srand(time(0));
  spinMove = rand()%6+1;
}


void checkChutes()
{
  if (newPosition == 16)
    newPosition = 6;
  else if (newPosition == 48)
    newPosition = 26;
  else if (newPosition == 49)
    newPosition = 11;
  else if (newPosition == 56)
    newPosition = 53;
  else if (newPosition == 62)
  newPosition = 53;
  else if (newPosition == 62)
    newPosition = 19;
  else if (newPosition == 64)
    newPosition = 60;
  else if (newPosition == 87)
    newPosition = 24;
  else if (newPosition == 93)
    newPosition = 73;
  else if (newPosition == 95)
    newPosition = 75;
  else  if (newPosition == 98)
    newPosition = 78;
  else
    newPosition = newPosition;
}
void checkLadders()
{
  if (newPosition == 4)
    newPosition = 14;
  else if (newPosition == 9)
    newPosition = 21;
  else if (newPosition == 23)
    newPosition = 44;
  else if (newPosition == 28)
    newPosition = 84;
  else if (newPosition == 36)
    newPosition = 44;
  else if (newPosition == 51)
    newPosition = 66;
  else if (newPosition == 71)
    newPosition = 90;
  else if (newPosition == 80)
    newPosition = 100;
  else
    newPosition = newPosition;
}
1
2
3
4
5
6
while(true)
{
// do game stuff
//check for a termination condition. If the user wants to quit 
break;
}


you also only need to call srand() once. In fact you should only call srand() once.
You could have a bool that's true when it's player one's turn and false otherwise. Your game int should probably be a bool too, although what you have works.

@pogrady
It's true that you only need to call srand() once, but why should you only call it once? It does no harm multiple times.
Last edited on
Topic archived. No new replies allowed.