Function SNAFU

Hello all:I'm coding a dice rolling program for school. The syntax on the function looks correct but my compiler pulls a red flag on the first bracket. then the whole program will not run.

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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;


  int rollDie(int min,int max);
  {/*<---error on this bracket */
  int roll;
  roll = (rand() % (max -min + 1)) + min;
  return roll;
  }

int main()
{
  
unsigned seed= time(0);
srand(seed);

bool exit;/*to leave game*/
int playerOneUpFirst=1;/*PLAYER ONE GOES FIRST*/
int playerTwoUpFirst=0; /*Player TWO GOES FIRST*/
int players;/*input for how many players*/
//int scoreLimit =100;
//int numb;
//int score1; 
//int score2;
int scoreTurn1;/* turn score for p1*/
int scoreTotal1;/* total scor for player 1*/
int scoreTotal2; /*total score fot p2*/
int scoreTurn2; /* turn score of p2*/
/*counter for one player score*/
//int score;/*score for one player*/
//int scoreTurn;/*score for player's turn on one player game*/
//int scoreTotal;/*score for player's total on one player game*/
//bool endTurn=false; /*ENDS CURRENT turn*/
//int count;/* */
//int currentScore =0;
//int lastRoll;
//char rollOrHold;
int die1 = 0;
int die2 =0;
char confirmation;
// int iCount;
// int player1Turn;
// int player2Turn;
// int (player2TotalScore);
const int maxValue = 6;
const int minValue = 1;
int rollDie(int,int); /*function to roll*/
int gamePlay=1; /*null funcution for while loops*/
cout << "One player or two?" << endl;
cin >>players;

if (players==1)
   {
   die1 = (rand() % (maxValue - minValue + 1)) + minValue;
   if (die1 != 1)
   {
     scoreTurn1 = die1;
     cout << "ok, one player!" << endl;
     cout << "you rolled a: "<< die1 << endl;
     cout << "Do you wish to roll again? (Y/N)" << endl;  
     cin >> confirmation; 
  
//logic to select y or n, of  user puts n the turn is over, if the player rolls a 1 they loose all pionts..   if player puts y
   while (confirmation== 'Y'||confirmation=='y')
   { 
    
   if (confirmation== 'Y'||confirmation=='y')
          { 
      
           die1 = rollDie(minValue,maxValue);
           die2 = rollDie(minValue,maxValue);
           cout <<"DEV:rolling...\n\n" <<"You rolled a "<< die1 <<endl;
          
           if (die1 != 1)
           {          
           scoreTurn1=scoreTurn1 + die1;
           cout << "Do you wish to roll again?(y/n) " << endl;
           cin >> confirmation; 
           while (confirmation != 'N' && confirmation !='n' && confirmation != 'Y' && confirmation!='y')
         {
           cout << "please enter a valid character" << endl;
           cout << "Do you wish to roll again?(y/n) " << endl;
           cin >> confirmation; 
         }
           }
          else
           {
             cout<< "You rolled a one and lost all your points."<<endl;
           scoreTurn1=0;           }
          
          }
         
         }
       if (confirmation == 'N'||confirmation =='n')
       {
         cout << string(20,'*') << endl;
         cout << "Turn end. Your score for this turn is "<< scoreTurn1 << ". "<< endl;
         scoreTotal1 = scoreTotal1 + scoreTurn1;
         cout<< "Total score is:" << scoreTotal1 << endl;
         players=0;
       }
   }  
/*two player game*/
if (players==2)
{
 cout << "Let's roll to see who goes first." << endl;

 cout << "Player one rolled a : " << die1 <<endl;

 cout << "Player two rolled a  :" << die2 <<endl;

 while (die1==die2)
 {
   die1= rollDie(minValue,maxValue); 
   die2= rollDie(minValue,maxValue); 
   if (die1>die2)
   {
     cout << "Player one you go first." <<endl;
   playerOneUpFirst=1;
   }
      if (die1<die2)
     {
     cout << "Player two you go first." <<endl;
     playerTwoUpFirst=1;
     }
       else 
       { 
        cout <<"You both tied. Let's roll again." <<endl;
       }

     if(playerOneUpFirst==1)
     {
       scoreTurn1=scoreTurn1 + die1;
       cout <<"Player one rolled a :" << die1 <<endl;
       cout << "Do you wish to roll again?(y/n) " << endl;
       cin >> confirmation;
      } 
        while (confirmation != 'N' && confirmation !='n' && confirmation != 'Y' && confirmation!='y')
       {
         while (confirmation== 'Y'||confirmation=='y')
         {      
           cout <<"DEV:rolling...\n\n" <<"You rolled a "<< die1 <<endl;
         }  
           if (die1 != 1)
           {          
           scoreTurn1=scoreTurn1 + die1;
           cout << "Do you wish to roll again?(y/n) " << endl;
           cin >> confirmation; 
        
         while (confirmation != 'N' && confirmation !='n' && confirmation != 'Y' && confirmation!='y')
         {
          cout << "please enter a valid character" << endl;
          cout << "Do you wish to roll again?(y/n) " << endl;
          cin >> confirmation; 
         }
           }
           else
           {
             cout<< "You rolled a one and lost all your points."<<endl;
             scoreTurn1=0;
          }
           if (confirmation == 'N'||confirmation =='n')
          {
          cout << string(20,'*') << endl;
          cout << "Turn end. Your score for this turn is "<< scoreTurn1 << ". "<< endl;
          scoreTotal1 = scoreTotal1 + scoreTurn1;
          cout<< "Total score is:" << scoreTotal1 << endl;
          players=0;
          }

         while(gamePlay==1);
       {
         if(playerTwoUpFirst==1)
         {
         scoreTurn1=scoreTurn1 + die2;
           cout <<"Player Two rolled a :" << die1 <<endl;
           cout << "Do you wish to roll again?(y/n) " << endl;
           cin >> confirmation;
         }

         while (confirmation== 'Y'||confirmation=='y')
         {      
         if (confirmation== 'Y'||confirmation=='y')
         {          
           cout <<"DEV:rolling...\n\n" <<"You rolled a "<< die1 <<endl;
         }

           if (die1 != 1)
           {          
           scoreTurn1=scoreTurn1 + die1;
           cout << "Do you wish to roll again?(y/n) " << endl;
           cin >> confirmation; 
          
           while (confirmation != 'N' && confirmation !='n' && confirmation != 'Y' && confirmation!='y')
         {
           cout << "please enter a valid character" << endl;
           cout << "Do you wish to roll again?(y/n) " << endl;
           cin >> confirmation; 

         }
         if (confirmation == 'N'||confirmation =='n')
       {
         cout << string(20,'*') << endl;
         cout << "Turn end. Your score for this turn is "<< scoreTurn1 << ". "<< endl;
         scoreTotal2 = scoreTotal2 + scoreTurn2;
         cout<< "Total score is:" << scoreTotal2 << endl;
         players=0;
      }
}

return 0;
}}}}}}}



Last edited on
closed account (SECMoG1T)
1
2
3
4
5
6
int rollDie(int min,int max);///remove this semicolon #to-fix
  {
  int roll;
  roll = (rand() % (max -min + 1)) + min;
  return roll;
  }
Last edited on
Topic archived. No new replies allowed.