Jack and Poy using Goto Statement??

#1 Hi.. so this is my jack n poy game. In the end of the program/round the computer will ask if i want to continue of not(exit). Some says use goto statement but i'm not aware of that goto statement and other says never ever use goto statement. So what should i do?? Any hint???

Do you want to continue the game?Y/N:

if Y(Yes)
the program will start again. Then if N(No).the programs end. Thnx..

#2 Additional problem is in the line 43. What if every round is tied then such time it is exactly 1000000?? But i think it is not posible.. But can anyone give me another way of it.. that when someone's score is 0 the game is done and no need of range like 1000000.

#3 Another is: any hint of keyboard symbols of rock??? hahah i made a circle to illustrate it.. any other???

#4 When i type an any key except numbers the program will infinite loop..

Enter your choice (1)Rock (2)Paper (3)Scissors: ;

But it's not a big deal, i will make an instruction of the game that 1,2,3 is only the key to press when choosing.
but any hint???

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
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>


 void main()
 {

 clrscr();

 int rounds,input,comp,score=3,cscore=3;


 for(int a=8;a<19;a++)
 {
 gotoxy(40,a);
 textcolor(2);
 cprintf("*");
 }

 for(int b=22;b<35;b++)
 {
 gotoxy(40,b);
 textcolor(100);
 cprintf("*");
 }

 gotoxy(20,9);
 textcolor(CYAN);
 cprintf("YOU");

 gotoxy(56,9);
 textcolor(GREEN);
 cprintf("COMPUTER");

 gotoxy(40,20);
 textcolor(LIGHTBLUE);
 cprintf("VS");

 gotoxy(20,12);
 textcolor(BROWN);
 cprintf("Lives:%d",score);
 gotoxy(56,12);
 textcolor(YELLOW);
 cprintf("Lives:%d",cscore);

 for(rounds=1;rounds<=1000000;rounds++)
 {
 gotoxy(69,5);
 printf("   ");
 gotoxy(35,3);
 textcolor(LIGHTRED);
 cprintf("JACK AND POY GAME");

 gotoxy(20,5);
 textcolor(LIGHTBLUE);
 cprintf("Enter your choice (1)Rock (2)Paper (3)Scissors:  ");
 scanf("%d",&input);

 while(input<1||input>3)
 {
 gotoxy(27,6);
 printf("%d is not a valid number!\n",input);
 gotoxy(17,7);
 printf("Please select 1 for Rock, 2 for Paper, and 3 for Scissors:");
 scanf("%d",&input);
 gotoxy(17,7);
 printf("                                                               ");
 gotoxy(27,6);
 printf("                                                               ");
 gotoxy(69,5);
 printf("   ");
 }

 if(input==1){

 textcolor(LIGHTGREEN);
 gotoxy(19,16);
 cprintf("  ROCK   ");


 gotoxy(17,18);cprintf("     **     ");
 gotoxy(17,19);cprintf("  *      *  ");
 gotoxy(17,20);cprintf(" *        * ");
 gotoxy(17,21);cprintf("*          *");
 gotoxy(17,22);cprintf("*          *");
 gotoxy(17,23);cprintf(" *        * ");
 gotoxy(17,24);cprintf("  *      *  ");
 gotoxy(17,25);cprintf("     **     ");

 }
 else if(input==2){
 gotoxy(19,16);
  textcolor(LIGHTBLUE);
 cprintf("  PAPER  ");

 gotoxy(17,18);cprintf("            ");
 gotoxy(17,19);cprintf("   -------  ");
 gotoxy(17,20);cprintf("  |   ___ | ");
 gotoxy(17,21);cprintf("  | _____ | ");
 gotoxy(17,22);cprintf("  |  ___  | ");
 gotoxy(17,23);cprintf("  | _____ | ");
 gotoxy(17,24);cprintf("  |       | ");
 gotoxy(17,25);cprintf("   -------  ");
 }
 else if(input==3){
 gotoxy(20,16);
 textcolor(LIGHTRED);
 cprintf("SCISSORS" );


 gotoxy(20,18);cprintf("             ");
 gotoxy(17,19);cprintf("    \\    /  ");
 gotoxy(17,20);cprintf("     \\  /   ");
 gotoxy(17,21);cprintf("      \\/    ");
 gotoxy(17,22);cprintf("      /\\    ");
 gotoxy(17,23);cprintf("     /  \\   ");
 gotoxy(17,24);cprintf("   ( )  ( )  ");
 gotoxy(17,25);cprintf("             ");
 }


 comp=1+rand() % 3;
 srand(time(0));
 if(comp==1){
 gotoxy(56,16);
 textcolor(MAGENTA);
 cprintf("  ROCK  ");


 gotoxy(55,18);cprintf("     **     ");
 gotoxy(55,19);cprintf("  *      *  ");
 gotoxy(55,20);cprintf(" *        * ");
 gotoxy(55,21);cprintf("*          *");
 gotoxy(55,22);cprintf("*          *");
 gotoxy(55,23);cprintf(" *        * ");
 gotoxy(55,24);cprintf("  *      *  ");
 gotoxy(55,25);cprintf("     **     ");
 }
 else if(comp==2){
 gotoxy(56,16);
 textcolor(YELLOW);
 cprintf("  PAPER ");


 gotoxy(55,18);cprintf("            ");
 gotoxy(55,19);cprintf("   -------  ");
 gotoxy(55,20);cprintf("  |   ___ | ");
 gotoxy(55,21);cprintf("  | _____ | ");
 gotoxy(55,22);cprintf("  |  ___  | ");
 gotoxy(55,23);cprintf("  | _____ | ");
 gotoxy(55,24);cprintf("  |       | ");
 gotoxy(55,25);cprintf("   -------  ");
 }
 else if(comp==3){
 gotoxy(56,16);

 textcolor(GREEN);
 cprintf("SCISSORS");


 gotoxy(55,18);cprintf("             ");
 gotoxy(55,19);cprintf("    \\    /  ");
 gotoxy(55,20);cprintf("     \\  /   ");
 gotoxy(55,21);cprintf("      \\/    ");
 gotoxy(55,22);cprintf("      /\\    ");
 gotoxy(55,23);cprintf("     /  \\   ");
 gotoxy(55,24);cprintf("   ( )  ( )  ");
 gotoxy(55,25);cprintf("             ");

 }



 if(input==comp){
 gotoxy(25,40);
 textcolor(LIGHTMAGENTA);
 cprintf("You and the computer are tied");}

 else if(input==1&&comp==2 ||input==2&&comp==3 ||input==3&&comp==1){
 gotoxy(25,40);
 textcolor(GREEN);
 cprintf("         Computer won        ");
 score--;
 }

  else if(input==3&&comp==2||input==2&&comp==1||input==1&&comp==3){
 gotoxy(25,40);
 textcolor(CYAN);
 cprintf("            You won          ");
 cscore--;
 }


 gotoxy(20,12);
 textcolor(BROWN);
 cprintf("Lives:%d",score);
 gotoxy(56,12);
 textcolor(YELLOW);
 cprintf("Lives:%d",cscore);


 if(score==0||cscore==0)
 {
 break;
 }
 }






 if(score>cscore){
 gotoxy(32,41);
 textcolor(MAGENTA);
 cprintf("YOU WON THE GAME!");
 }
 else if(score<cscore){
 gotoxy(32,41);
 textcolor(YELLOW);
 cprintf("YOU LOOSE THE GAME!");
 }





 getch();
 }
Oh, it is about "goto statement". Very different thing from "gotoxy function".

Goto statement is something like:

1
2
3
4
5
repeat:
//...
if (userResponse == 'Y') {
    goto repeat;
}


While "gotoxy" function is just the function to position cursor on the screen. Its only problem is that it is not standard, though I do not think it should trouble you much now.
Last edited on
I actually get it before I read your response but thank you very much for your effort :)


can you help me with the problem #4???
Do not care about #4 right now - you will found it yourself bit later. Currently it is more important to you to learn splitting program into smaller functions (and use indentation). I encourage you to read something on this since it will greatly help you. :)
Thanks a lot bro :) Where can i read some of that topics??
Topic archived. No new replies allowed.