Help with debugging

Hi all, I'm trying to code Pig and everything seems to be pretty much written up, however..

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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#include <iostream>
#include <string>
#include <ctime>
#include <cstdlib>


  using std::cout;
  using std::cin;
  using std::endl;
  using std::rand;
  using std::srand;
  using std::time;
  using std::string;

  string player1;
  string player2;


  int p1score = 0;
  int p2score = 0;
  int p1turn ( int p1total );
  int p2turn ( int p2total );
  int p1total = 0;
  int p2total = 0;
  int p1die = 0;
  int p2die = 0;
  int p1roll = 0;
  int p2roll = 0;
  char move;


int main ( void )
{
  
  srand(time(0));
  p1roll = rand() % 6 + 1;
  p2roll = rand() % 6 + 1;

  cout << "Welcome to Pigs!  The simple rule of this game is to roll"  << endl;
  cout << "the die and finish on a total score of 100 or more points." << endl << endl;


  cout << "Player 1, please enter your name: ";
  cin >> player1;
  cout << "Welcome, " << player1 << "."<< endl << endl;
  cout << "Player 2, please enter your name: "; 
  cin >> player2;
  cout << "Welcome, " << player2 << "."<< endl << endl;
  cout << "Let's begin!" << endl << endl;
  

  cout << "Your turn, "  << player1 << ".  Enter 1 to roll" << endl;
  cin >> move;
  
  
  int p1turn ( int p1total )
  {
    

    if ( p1roll >= 2 && p1roll <= 6 )
    {
      cout << player1 << " rolled a ";
      p1score += p1roll;
      cout << p1roll << "!";
      cout << player1 << "'s total score is: " << p1total << "." <<endl;
    }


    else if ( p1roll == 1 )
    {
      cout << "Bad luck, " <<player1 << " you rolled a ";
      p1roll;
      cout << " :(";
      cout << "Your total score is: " << p1score << endl;
      p2turn ( p2total );
    }

  }


  int p2turn ( int p2total )
  {
    if ( p2roll >=2 && p2roll <=6 )
    {
      cout << player2 << " rolled a ";
      p2score += p2roll;
      cout << p2roll;
      cout << player2 << "'s total score is: " << p2score << "." << endl;
    }


    else if ( p2roll == 1 )
    {
      cout << "Bad luck, " <<player2 << "you rolled a ";
      p1roll;
      cout << " :(";
      cout << "Your total score is: " <<p2score << endl;
      p1turn ( p1total );
    }
  }


  while ( p1score < 100 || p2score < 100 )
  {
    if ( move == 'r' )
    {
      cout << player1 << " has chosen to roll." << endl;
      p1turn ( p1total ) <<endl;
      cout << "Do you want to roll or stand?";
      cin >> move;
    }


    else if ( move == 'h' )
    {
      cout << player1 << " has decided to hold.  ";
      cout << player2 << "'s turn." << endl;
      p2turn ( p2total );
      cin >> move;
    }
  }


  if ( p1score >= 100 )
  {
    cout << player1 << "wins!" << endl;
  }


  else if ( p2score >= 100 )
  { 
    cout << player2 << "wins!" << endl;
  }



  return 0;
}


Is apparently buggy to the compiler and a red line appears under the { after 'int p1turn ( p1total ) in the main body. Any ideas?
It looks like you are trying to create different functions inside of the main function which you are not allowed to do (p1turn, p2turn). Although they are not returning anything so not 100% sure what you are trying to do there.

If you are intending for these to be functions move them outside of main somewhere.
Topic archived. No new replies allowed.