2 doesn't execute after 1- runtime error

The second time this program is run, meaning after inputting 'y' to "Would You Like To Try The Program Again? (y/n): ", it doesn't output the picture. I solved the last problem i put up but don't know why there is a runtime error when i input 1, solve it, input 'y', then input 2. Anyone here knows why?

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
#include <cstdlib>
#include <iostream>
#include <cctype>

using namespace std;

void FirstWord(char First[4], int &mark)
{
     char str[4];
     int result, i;
     cout<<"1 - ADL: ";
     cin>>First;
     str[sizeof(str)-1]='\0';
     for(i=0; First[i]!='\0'; i++)
     {
                    str[i]=toupper(First[i]);
     }
     result=strcmp(str,"LAD");
     if(result==0)
     {
                  mark=mark+10;
                  cout<<"Well Done! Your Marks Is: "<<mark;
                  cout<<endl<<endl<<endl;
                      
     }
     else
     {
         cout<<"Sorry! You Are Wrong! Your Marks Is: "<<mark;
         cout<<endl<<endl<<endl;
                       
     }
}

void SecondWord(char Second[5], int &mark)
{
     char str[5];
     int result, i;
     cout<<"2 - FTRU: ";
     cin>>Second;
     str[sizeof(str)-1]='\0';
     for(i=0; Second[i]!='\0'; i++)
     {
                    str[i]=toupper(Second[i]);
     }
     result=strcmp(str,"TURF");
     if(result==0)
     {
                  mark=mark+10;
                  cout<<"Well Done! Your Marks Is: "<<mark;
                  cout<<endl<<endl<<endl;
                  
                  
     }
     else
     {
         cout<<"Sorry! You Are Wrong! Your Marks Is: "<<mark;
         cout<<endl<<endl<<endl;
                       
     }
}

void ThirdWord(char Third[6], int &mark)
{
     char str[6];
     int result, i;
     cout<<"3 - TLSPA: ";
     cin>>Third;
     str[sizeof(str)-1]='\0';
     for(i=0; Third[i]!='\0'; i++)
     {
                    str[i]=toupper(Third[i]);
     }
     result=strcmp(str,"SPLAT");
     if(result==0)
     {
                  mark=mark+10;
                  cout<<"Well Done! Your Marks Is: "<<mark;
                  cout<<endl<<endl<<endl;
                  
     }
     else
     {
         cout<<"Sorry! You Are Wrong! Your Marks Is: "<<mark;
         cout<<endl<<endl<<endl;              
     }
}

void FourthWord(char Fourth[7], int &mark)
{
     char str[7];
     int result, i;
     cout<<"4 - GEGLJI: ";
     cin>>Fourth;
     str[sizeof(str)-1]='\0';
     for(i=0; Fourth[i]!='\0'; i++)
     {
                    str[i]=toupper(Fourth[i]);
     }
     result=strcmp(str,"JIGGLE");
     if(result==0)
     {
                  mark=mark+10;
                  cout<<"Well Done! Your Marks Is: "<<mark;
                  cout<<endl<<endl<<endl;
                  
     }
     else
     {
         cout<<"Sorry! You Are Wrong! Your Marks Is: "<<mark;
         cout<<endl<<endl<<endl;              
     } 
}

void FifthWord(char Fifth[8], int &mark)
{
     char str[8];
     int result, i;
     cout<<"5 - HIPTURG: ";
     cin>>Fifth;
     str[sizeof(str)-1]='\0';
     for(i=0; Fifth[i]!='\0'; i++)
     {
                    str[i]=toupper(Fifth[i]);
     }
     result=strcmp(str,"UPRIGHT");
     if(result==0)
     {
                  mark=mark+10;
                  cout<<"Well Done! Your Marks Is: "<<mark;
                  cout<<endl<<endl<<endl;
                  
     }
     else
     {
         cout<<"Sorry! You Are Wrong! Your Marks Is: "<<mark;
         cout<<endl<<endl<<endl;              
     }
}

void SixthWord(char Sixth[9], int &mark)
{
     char str[9];
     int result, i;
     cout<<"6 - LUKNCEKS: ";
     cin>>Sixth;
     str[sizeof(str)-1]='\0';
     for(i=0; Sixth[i]!='\0'; i++)
     {
                    str[i]=toupper(Sixth[i]);
     }
     result=strcmp(str,"KNUCKLES");
     if(result==0)
     {
                  mark=mark+10;
                  cout<<"Well Done! Your Marks Is: "<<mark;
                  cout<<endl<<endl<<endl;
                  
     }
     else
     {
         cout<<"Sorry! You Are Wrong! Your Marks Is: "<<mark;
         cout<<endl<<endl<<endl;              
     }
}

void SeventhWord(char Seventh[10], int &mark)
{    
     char str[10];
     int result, i;
     cout<<"7 - RIAUCEVSO: ";
     cin>>Seventh;
     str[sizeof(str)-1]='\0';
     for(i=0; Seventh[i]!='\0'; i++)
     {
                    str[i]=toupper(Seventh[i]);
     }
     result=strcmp(str,"VERACIOUS");
     if(result==0)
     {
                  mark=mark+10;
                  cout<<"Well Done! Your Marks Is: "<<mark;
                  cout<<endl<<endl<<endl;
                  
     }
     else
     {
         cout<<"Sorry! You Are Wrong! Your Marks Is: "<<mark;
         cout<<endl<<endl<<endl;              
     }
}

void EightWord(char Eight[11], int &mark)
{
     char str[11];
     int result, i;
     cout<<"8 - AFNGIGRYAI: ";
     cin>>Eight;
     str[sizeof(str)-1]='\0';
     for(i=0; Eight[i]!='\0'; i++)
     {
                    str[i]=toupper(Eight[i]);
     }
     result=strcmp(str,"GRATIFYING");
     if(result==0)
     {
                  mark=mark+10;
                  cout<<"Well Done! Your Marks Is: "<<mark;
                  cout<<endl<<endl<<endl;
                  
     }
     else
     {
         cout<<"Sorry! You Are Wrong! Your Marks Is: "<<mark;
         cout<<endl<<endl<<endl;              
     }
}

void NinthWord(char Ninth[12], int &mark)
{
     char str[12];
     int result, i;
     cout<<"9 - KTAPLOZNOKO: ";
     cin>>Ninth;
     str[sizeof(str)-1]='\0';
     for(i=0; Ninth[i]!='\0'; i++)
     {
                    str[i]=toupper(Ninth[i]);
     }
     result=strcmp(str,"ZOOPLANKTON");
     if(result==0)
     {
                  mark=mark+10;
                  cout<<"Well Done! Your Marks Is: "<<mark;
                  cout<<endl<<endl<<endl;
                  
     }
     else
     {
         cout<<"Sorry! You Are Wrong! Your Marks Is: "<<mark;
         cout<<endl<<endl<<endl;              
     }
}

void TenthWord(char Tenth[13], int &mark)
{
     char str[13];
     int result, i;
     cout<<"10 - NNNEEASIFCRK: ";
     cin>>Tenth;
     str[sizeof(str)-1]='\0';
     for(i=0; Tenth[i]!='\0'; i++)
     {
                    str[i]=toupper(Tenth[i]);
     }
     result=strcmp(str,"FRANKINCENSE");
     if(result==0)
     {
                  mark=mark+10;
                  cout<<"Well Done! Your Marks Is: "<<mark;
                  cout<<endl<<endl<<endl;             
     }
     else
     {
         cout<<"Sorry! You Are Wrong! Your Marks Is: "<<mark;
         cout<<endl<<endl<<endl;              
     }
}
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
int main(int argc, char *argv[], int &Score)
{
    char Str[12], again;
    int choice;
    system("color F2");
    cout<<"Welcome To Computer Scrabble!"<<endl<<endl<<endl;
    cout<<"Please Choose The Following Options:"<<endl;
    cout<<"1.Play Scrabble."<<endl;
    cout<<"2.Developers Picture."<<endl;
    cout<<"3.Quit."<<endl<<endl<<endl;
    cin>>choice;
    cout<<endl<<endl;                                                   
    if(choice==1)
    {
                 cout<<"Please Re-arrange The Following Words: "<<endl<<endl<<endl;
                 FirstWord(Str, Score=0);
                 SecondWord(Str, Score);
                 ThirdWord(Str, Score);
                 FourthWord(Str, Score);
                 FifthWord(Str, Score);
                 SixthWord(Str, Score);
                 SeventhWord(Str, Score);
                 EightWord(Str, Score);
                 NinthWord(Str, Score);
                 TenthWord(Str, Score);
                 cout<<Score<<endl<<endl<<endl;
                 cout<<"Would You Like To Try The Program Again? (y/n): ";
                 cin>>again;
                 cout<<endl<<endl;
                 while(again=='y'||again=='Y')
                 {                              
                                   cout<<"1.Play Scrabble."<<endl;
                                   cout<<"2.Developers Picture."<<endl;
                                   cout<<"3.Quit."<<endl<<endl<<endl;
                                   cin>>choice;
                                   cout<<endl<<endl;
                                   if(choice==1)
                                   {
                                                cout<<"Please Re-arrange The Following Words: "<<endl<<endl<<endl;
                                                FirstWord(Str, Score=0);
                                                SecondWord(Str, Score);
                                                ThirdWord(Str, Score);
                                                FourthWord(Str, Score);
                                                FifthWord(Str, Score);
                                                SixthWord(Str, Score);
                                                SeventhWord(Str, Score);
                                                EightWord(Str, Score);
                                                NinthWord(Str, Score);
                                                TenthWord(Str, Score);
                                                cout<<Score<<endl<<endl<<endl;
                                                cout<<"Would You Like To Try The Program Again? (y/n): ";
                                                cin>>again;
                                                cout<<endl<<endl;
                                   }
                                   if(choice==2)
                                   {
                                                system("Team.jpg");
                                                cout<<"Would You Like To Try The Program Again? (y/n): ";
                                                cin>>again;
                                                cout<<endl<<endl;
                                   }
                                   if(choice==3)
                                   {
                                                exit(0);
                                   }
                 }
                 if(again=='n'||again=='N')
                 {                              
                                   exit(0);                                                                    
                 }                                                        
    }
    if(choice==2)
    {
                 system("Team.jpg");
                 cout<<"Would You Like To Try The Program Again? (y/n): ";
                 cin>>again;
                 cout<<endl<<endl;
                 while(again=='y'||again=='Y')
                 {                              
                                   cout<<"1.Play Scrabble."<<endl;
                                   cout<<"2.Developers Picture."<<endl;
                                   cout<<"3.Quit."<<endl<<endl<<endl;
                                   cin>>choice;
                                   cout<<endl<<endl;
                                   if(choice==1)
                                   {
                                                cout<<"Please Re-arrange The Following Words: "<<endl<<endl<<endl;
                                                FirstWord(Str, Score=0);
                                                SecondWord(Str, Score);
                                                ThirdWord(Str, Score);
                                                FourthWord(Str, Score);
                                                FifthWord(Str, Score);
                                                SixthWord(Str, Score);
                                                SeventhWord(Str, Score);
                                                EightWord(Str, Score);
                                                NinthWord(Str, Score);
                                                TenthWord(Str, Score);
                                                cout<<Score<<endl<<endl<<endl;
                                                cout<<"Would You Like To Try The Program Again? (y/n): ";
                                                cin>>again;
                                                cout<<endl<<endl;
                                   }
                                   if(choice==2)
                                   {
                                                system("Team.jpg");
                                                cout<<"Would You Like To Try The Program Again? (y/n): ";
                                                cin>>again;
                                                cout<<endl<<endl;
                                   }
                                   if(choice==3)
                                   {
                                                exit(0);
                                   }
                 }
                 if(again=='n'||again=='N')
                 {                              
                                   exit(0);                                                                     
                 }                                                        
    }
    if(choice==3)
    {
                 exit(0);
    }
    if(choice!=1&&choice!=2&&choice!=3)
    {
                                       cout<<"Please Enter Menu Numbers 1 to 3 Only!";
                                       cout<<endl<<endl<<endl;
    }                                 
    system("PAUSE");
    return EXIT_SUCCESS;
}
What does the main function have in it?

Edit: Ninjared!
Last edited on
First off, your while loops are unnessecary. They repeat the same action as before. I personally prefer the do while loop, write your statements and never have to declare the item you're comparing. Secondly, instead of the exit(0) function, why not use return 0? Third...ly? You made a lot of functions that do exactly the same thing. Think about passing the string as a parameter instead of writing individual functions for one to two strings.

As for your program terminating, all I can tell is that it should loop, given the conditions you specified, indefinitely.
As for your program terminating, all I can tell is that it should loop, given the conditions you specified, indefinitely.


Volatile Pulse, thanks for the reply and the suggestions. Haha, I'm just doing that to gain my marks in my course =P. However, I found that it doesn't loop indefinitely but somehow just terminates. Can you tell me why?
Last edited on
LOL Moschops but that doesn't help.
This is invalid declarration of the main

int main(int argc, char *argv[], int &Score)

and I do not understand why is it needed in general?!
Thanks vlad. Can you point out what's invalid in the declaration?
The presence of the third parameter is invalid.

int main(int argc, char *argv[], int &Score)
Topic archived. No new replies allowed.