LOST!!!!

need help finishing up program for class, no tutoring at school to help. i have the hole be random from 0 to 5000feet. then allow players to alternate hitting ball. I cant get the game to be over if someone wins. how would i do this?
A)one player hits the ball in the hole, they win
b)both players hits the ball in hole, nobody wins
c)1 player hits ball out of bounds they lose
d)both players hits out of bounds they both lose
e)if nobody hits ball in hole the closest to the hole wins.

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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
 void swampGolf()
{
    char hole,option,dis,rad;
    double xPlayer,yPlayer,xHole,yHole,horizontalAngleB;
    double horizontalDistance,x1,x2,y1,y2,distance,dx,dy;
    int missed=0,count=0,rounds=6;
    
    
    srand(time(0));
    for(int x=0;x<1;++x)
    xHole=1+(rand() % 5000);
    yHole=xHole;
    
    srand(time(0));
    for(int x=0;x<1;++x)
    xPlayer=1+(rand() % 5000);
    yPlayer=xPlayer;
    
    
    cout<<"Welcome to Swamp Golf!!!"<<endl;
    cout<<"First player would be Tiger Woods!"<<endl;
    cout<<"Second player is Phil Mickelson!!"<<endl;
    cout<<"The goal of Swamp Golf is to try to hit a golf ball";
    cout<<" using only 'irons'."<<endl;
    cout<<"Let the game begin"<<endl<<endl;
    
    cout<<"What set of difficulty do you want to play?"<<endl;
    cout<<"(1)Low with a Hole Radius(feet) of 10"<<endl;
    cout<<"(2)Medium with a Hole Radius(feet) of 5"<<endl;
    cout<<"(3)High with a Hole Radius(feet) of 2"<<endl;
    cin>>hole;
 

//Tiger Woods
for(double round=1;round<rounds;++round)
    {
    
    
    cout<<"Tiger you're up."<<endl;
    cout<<"What would you like to do?"<<endl<<endl;
    
    cout<<"(a)Hit the ball"<<endl;
    cout<<"(b)Use the compass/range-finder to find the angle";
    cout<<" and distance to the hole"<<endl;
    cout<<"(c)Pass(do nothing,ex:when ball is close to hole"<<endl;
    cout<<"(d)Quit the game(and default)"<<endl<<endl;
    cin>>option;
        
if(option=='a')
    {
    
    if(hole=='1')
        {
        horizontalDistance=stroke();
        cout<<"horizontalDistance="<<horizontalDistance<<endl<<endl;
        
        missed=horizontalDistance-xHole;
    
        
        if(missed<=10&&missed>=-10)
        {
            cout<<"Congrats you made it!"<<endl;
        
        }
        else
            ++horizontalDistance;
        }
        
    else if(hole=='2')
        {
            horizontalDistance=stroke();
            cout<<"horizontalDistance="<<horizontalDistance<<endl<<endl;
            
            missed=horizontalDistance-xHole;
            
            
            if(missed<=5&&missed>=-5)
            {
                cout<<"Congrats you made it!"<<endl;
            }
            else
                ++horizontalDistance;
        }
        
    else if(hole=='3')
        {
            horizontalDistance=stroke();
            cout<<"horizontalDistance="<<horizontalDistance<<endl<<endl;
            
            missed=horizontalDistance-xHole;
            
        
            if(missed<=2&&missed>=-2)
            {
              cout<<"Congrats you made it!"<<endl;
            }
            else
                ++horizontalDistance;
        }
    if(horizontalDistance<0&&horizontalDistance>5000)
            cout<<"OUT of BOUNDS!!"<<endl<<endl;
        
        
        xPlayer=horizontalDistance+horizontalDistance;
        
        displayMap(xPlayer,yPlayer,xHole,yHole);
        
        
    }
    else if(option=='b')
    {
        cout<<"Do you want to find distance?(y/n)"<<endl<<endl;
        cin>>dis;
        
        while(dis !='y'&& dis!='n')
        {cout<<endl<<"Please enter 'y' or 'n'"<<endl<<endl;
            cin>>dis;}
        
        cout<<"Do yo want to find the Radius?(y/n)"<<endl<<endl;
        cin>>rad;
        
        while(rad !='y'&& rad!='n')
        {cout<<endl<<"Please enter 'y' or 'n'"<<endl<<endl;
            cin>>rad;}
        
        if(dis=='y'){
            
        distanceInput(x1,x2,y1,y2);
        distance=distanceTotal(x1,x2,y1,y2);
        displayDistance(distance);}
        
        if(rad=='y')
        {angleInput(x1,x2,y1,y2);
        horizontalAngleB= angleTotal(x1,x2,y1,y2,dx,dy);
        displayAngle(horizontalAngleB);}
        
        
    }
    
    
    else if(option=='c')
    {
        cout<<"Pass"<<endl<<endl;
    }
    
    else if(option=='d')
    {
     cout<<"Game Over you win Phil!!"<<endl<<endl;
        cout<<endl<<endl;
    }

    
//Phil Mickelson
    cout<<"Phil you're up."<<endl;
    cout<<"What would you like to do?"<<endl<<endl;
    
    cout<<"(a)Hit the ball"<<endl;
    cout<<"(b)Use the compass/range-finder to find the angle";
    cout<<" and distance to the hole"<<endl;
    cout<<"(c)Pass(do nothing,ex:when ball is close to hole"<<endl;
    cout<<"(d)Quit the game(and default)"<<endl<<endl;
    cin>>option;
    
    if(option=='a')
    {
        
        if(hole=='1')
        {
            horizontalDistance=stroke();
            cout<<"horizontalDistance="<<horizontalDistance<<endl<<endl;
            
            missed=horizontalDistance-yHole;
            cout<<"   "<<yHole<<endl;
            
            ++count;
            if(missed<=10&&missed>=-10)
            {
                cout<<"Congrats you made it!"<<endl;
                
            }
            else
                ++missed;
        }
        
        else if(hole=='2')
        {
            horizontalDistance=stroke();
            cout<<"horizontalDistance="<<horizontalDistance<<endl<<endl;
            
            missed=horizontalDistance-yHole;
            
            ++count;
            if(missed<=5&&missed>=-5)
            {
                cout<<"Congrats you made it!"<<endl;
            }
            else
                ++missed;
        }
        
        else if(hole=='3')
        {
            horizontalDistance=stroke();
            cout<<"horizontalDistance="<<horizontalDistance<<endl<<endl;
            
            missed=horizontalDistance-yHole;
            
            ++count;
            if(missed<=2&&missed>=-2)
            {
                cout<<"Congrats you made it!"<<endl;
            }
            else
                ++missed;
        }
    
     if(horizontalDistance<0&&horizontalDistance>5000)
         cout<<"OUT of BOUNDS!!"<<endl<<endl;
        
        displayMap(xPlayer,yPlayer,xHole,yHole);
        
        
    }
    else if(option=='b')
    {
        missed=horizontalDistance-yHole;
        cout<<"Missed by="<<missed<<endl<<endl;
    }
    
    
    else if(option=='c')
    {
        cout<<"Pass"<<endl<<endl;
    }
    
    else if(option=='d')
    {
        cout<<"Game Over you win Tiger!!"<<endl<<endl;
    }
    
    
    cout<<"Rounds="<<round<<endl<<endl;
    
    
    }

    cout<<"Game Over"<<endl;
    if(xPlayer>yPlayer)
    cout<<"Tiger Woods is the winner!"<<endl<<endl;
    else if(yPlayer>xPlayer)
    cout<<"Phil Mickelson is the winner!"<<endl<<endl;
    
    
    }



double stroke()
{
    double elevationAngleE,horizontalDistance,initialVelocityV;
    char type;
    double force;
    
    cout<<"What type of club would you like to use";
    cout<<"(3)-iron, (5)-iron, (7)-iron, or (9)-iron?"<<endl;
    cin>>type;
    
    cout<<"What is the % of force of the swing (0 to 100%)";
    cout<<" example: 50% will be type in as 0.5"<<endl;
    cin>>force;
    while(force<0||force>1)
    {
        cout<<endl<<"Please re-enter Force";
        cout<<" needs to be greater than 0 and less than 1.";
        cout<<"(example: 50% will be type in as 0.5)"<<endl;
        cin>>force;
    }
    if(type=='3')
        elevationAngleE=20;
    else if(type=='5')
        elevationAngleE=40;
    else if(type=='7')
        elevationAngleE=60;
    else
        elevationAngleE=80;
    
    initialVelocityV=force*150;
    
    
    horizontalDistance=elevationTotal(elevationAngleE,initialVelocityV);
    return horizontalDistance;
}

void displayDestination(double x2, double y2)
{
    cout<<"x Coordinates of destination(feet)="<<x2<<endl<<endl;
    cout<<"y Coordinates of destination(feet)="<<y2<<endl<<endl;
}
Topic archived. No new replies allowed.