By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,984 Members | 1,025 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,984 IT Pros & Developers. It's quick & easy.

declaration syntax error

samrah
P: 3
i cannot run this program just because of 1 declaration syntax error.
also there is 1 warning which says"unreachable code".
what to do??
Expand|Select|Wrap|Line Numbers
  1. #include<iostream.h>
  2. #include<stdio.h>
  3. #include<conio.h>
  4. #include<iomanip.h>
  5. #include<process.h>
  6. int sum=0,sum1=0,sum2=0,l,r,sum3=0;
  7. void board();
  8. int checkwin();
  9. char square[10] = {'o','1','2','3','4','5','6','7','8','9'};
  10.  
  11. void main()
  12. {
  13. clrscr();
  14.  
  15. void pg3();
  16.  
  17. pg3();
  18.  
  19. void pg1();
  20.  
  21. pg1();
  22.  
  23. void pg4();
  24.  
  25. pg4();
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32. getch();
  33.  
  34. }
  35.  
  36.  
  37. void pg3()
  38. {
  39. cout<<"\n\n";
  40. cout<<"\n\t\t@@@@ @@@@ @ @ @@@@ @ @ @@@@@ @@@@ @@@@ \n";
  41. cout<<"\n\t\t@ @  @ @@ @@ @ @ @ @@ @\n";
  42. cout<<"\n\t\t@  @ @ @ @ @ @@@ @ @  @ @@@ @@@\n";
  43. cout<<"\n\t\t@  @ @ @  @ @ @ @ @ @ @ @\n";
  44. cout<<"\n\t\t@@@@ @@@@ @ @ @ @@@@ @ @@@@ @ @\n\n\n\n\n\n\n\n";
  45. cout<<"\n\t\t\t\t@@@@ @@@@ @@@@ @@@@@ @@@@ @@@@ @@@@@\n";
  46. cout<<"\n\t\t\t\t@ @ @ @ @  @ @  @ @ @\n";
  47. cout<<"\n\t\t\t\t@@@ @@@ @ @ @ @@@ @  @ \n";
  48. cout<<"\n\t\t\t\t@  @ @ @ @ @@ @ @  @ \n";
  49. cout<<"\n\t\t\t\t@  @ @ @@@@ @@@ @@@@ @@@@ @ \n\n\n\n\n\n\n";
  50. cout<<"\n\n\n\n";
  51. cout<<"\n\t\t\t\tCREATED BY:";
  52. cout<<"\n\t\t\t\tSAMRAH ZAKI ANSARI XI B";
  53. cout<<"\n\t\t\t\tPALAK TAKHTANI XI A";
  54. getch();
  55. }
  56.  
  57. void pg1()
  58.  
  59. {
  60. clrscr();
  61. cout<<"\n";
  62. for(int m=1;m<2;++m)
  63. {
  64. for(int n=1;n<=10;++n)
  65. {
  66. cout<<"";
  67. }
  68. cout<<"\n";
  69. }
  70. for(m=1;m<8;++m)
  71. {
  72. cout<<"\n";
  73. }
  74. cout<<"\n\n\n\t""WELCOME TO WORLD'S LARGEST AMUSEMENT PARK \n\n";
  75. cout<<"\n\n\n\n\n\n";
  76. //Program to print heart pattern
  77.  int n,i,j;
  78.  n=20;
  79.  if(n%2==0)
  80.   n++;
  81.  cout<<"\n\n"<<"\tM A G I C  K I N G D O M\n";
  82.  for(i=0;i<n;i++)
  83.  {
  84.   for(j=0;j<n;j++)
  85.   {
  86.    if(i==0&&(j>=n/5&&j<=n/2-n/5)||i==0&&(j>=n/2+n/5&&j<=(n-1)-n/5))
  87.     cout<<"* ";
  88.    else if(i>0&&i<=n/5&&(j==n/5-i||j==n/2+n/5-i||j==n/2-n/5+i||j==(n-1)-n/5+i))
  89.     cout<<"* ";
  90.    else if((i>n/5&&i<=n/2)&&(j==0||j==n-1))
  91.     cout<<"* ";
  92.    else if(i>n/2&&(j==i-n/2||j==(n-1)-(i-n/2)))
  93.     cout<<"* ";
  94.    else cout<<"  ";
  95.   }
  96.   cout<<"\n";
  97.  }
  98.  cout<<"\tM A G I C  K I N G D O M\n";
  99.  getch();
  100. }
  101.  
  102. void pg4()
  103. { clrscr();
  104. float c,d,e,f,g;
  105. cout<<"\n\n\n\n";
  106. cout<<"\t                 ENTRY FEES                       \n";
  107. cout<<"\t****************************************************\n";
  108. cout<<"\t|---------------------|---------------------|\n";
  109. cout<<"\t|               |    PRICES      |\n";
  110. cout<<"\t|    CRITERIA   |----------------|\n";
  111. cout<<"\t|              |  CHILDREN  |  ADULTS  |\n";
  112. cout<<"\t|-----------------|------------|------------|\n";
  113. cout<<"\t|              |      |        |\n";
  114. cout<<"\t| HEIGHT BETWEEN 3.5 TO 5 FEET | ?500/- | ?550/- |\n";
  115. cout<<"\t|              |      |        |\n";
  116. cout<<"\t| HEIGHT ABOVE 5 FEET  | ?600/- | ?800/- |\n";
  117. cout<<"\t|              |      |        |\n";
  118. cout<<"\t| SENIOR CITIZENS (ABOVE 60 YRS) | ?500/- |\n";
  119. cout<<"\t|              |      |        |\n";
  120. cout<<"\t|---------------------|---------------------|\n\n\n";
  121. cout<<"\t               *******************************\n\n";
  122. cout<<"\t    HURRY !!!!! CHILDREN BELOW 3.5 FEET GET FREE ENTRY!!!!!!!!\n\n";
  123. cout<<"\t *********************************\n\n";
  124.  
  125. cout<<"\n ENTER NO.OF CHILDREN BETWEEN HEIGHT 3.5 TO 5 FEET";
  126. cin>>c;
  127. cout<<"\n ENTER NO.OF ADULTS BETWEEN HEIGHT 3.5 TO 5 FEET";
  128. cin>>d;
  129. cout<<"\n ENTER NO.OF CHILDREN ABOVE HEIGHT 5 FEET";
  130. cin>>e;
  131. cout<<"\n ENTER NO.OF ADULTS ABOVE HEIGHT 5 FEET";
  132. cin>>f;
  133. cout<<"\n ENTER NO.OF SENIOR CITIZENS";
  134. cin>>g;
  135. sum=((c*500)+(d*550)+(e*600)+(f*800)+(g*500));
  136.  
  137. clrscr();
  138.  
  139.  
  140. cout<<"\n\n\n";
  141. for(int l=1;l<4;++l)
  142. cout<<"\n";
  143. for(int i=1;i<3;++i)
  144. {
  145. for(int j=1;j<81;++j)
  146. cout<<"";
  147. }
  148.  
  149. int a;
  150. cout<<"\n\t\t\t\t\tLIVE THE THRILL \n\n\n\n\n\n\n\n\nENTER INTO THE WORLD OF RIDES\n\n\n\n\n\n\t\t1.LAND PARADISE\n\n\n\n\n\t\t2.WATER PARADISE\n";
  151. for(int q=1;q<4;++q)
  152. cout<<"\n";
  153. for(int h=1;h<3;++h)
  154. {
  155. for(int k=1;k<81;++k)
  156. cout<<"";
  157. }
  158. cout<<"ENTER YOUR CHOICE (1/2)\n";
  159. cin>>a;
  160. switch(a) //land water choice
  161. {
  162. case 1:
  163. {
  164. clrscr();
  165. start:
  166. {
  167. cout<<"\t        LAND PARADISE\n";
  168. cout<<"\t      ^^^^^^^^^^^^^^^^^^^^ \n\n";
  169. cout<<"|-----------------|-------------------|------------------|\n";
  170. cout<<"| 1.KIDS RIDES    | 2.ADULT RIDES    | 3.FAMILY RIDES    |\n";
  171. cout<<"|-----------------|-------------------|------------------|\n";
  172. cout<<"| 1.BIG APPLE RS300/-| 1.SHOT N DROP RS400/-|1.MONSTERS IN MIST RS450/-|\n";
  173. cout<<"| 2.HAPPY SLEY RS325/-|2.TOP SPIN RS425/-|2.CRAZY CUPS RS475/-|\n";
  174. cout<<"| 3.           RS350/-|3.ENTERPRISE RS450/-|3.AQUA DRIVE RS500/-|\n";
  175. cout<<"| 4.CATERPILLAR RS375/-|4.RAINBOW RS475/-|4.PRABAL THE KILLER RS525/-|\n";
  176. cout<<"| 5.YARD TRAIN RS400/-|5.ZYCLONE RS500/-|5.MIRROR MAZE RS550/-|\n";
  177. cout<<"| 6.BOAT RIDE RS450/-|6.HOOLA LOOP RS550/-|6.HIGHWAY RS600/-|\n";
  178. cout<<"|-----------------|-------------------|------------------|\n";
  179.  
  180. int k,b;
  181. cout<<"\nENTER YOUR CHOICE \n1.KIDS RIDES\n2.ADULT RIDES\n3.FAMILY RIDES\n";
  182. cin>>b;
  183. switch(b)     //land choice
  184. {
  185. case 1:
  186. if(b==1)
  187. { cout<<"\nCHOOSE YOUR RIDE(1-6)";
  188. cin>>k;
  189. switch(k)    //sub choice
  190. {
  191. case 1:
  192. {if(k==1)
  193. sum1=sum1+300;}
  194. case 2:
  195. {if(k==2)
  196. sum1=sum1+325;}
  197. case 3:
  198. {if(k==3)
  199. sum1=sum1+350;}
  200. case 4:
  201. {if(k==4)
  202. sum1=sum+375;}
  203. case 5:
  204. {if(k==5)
  205. sum1=sum1+400;}
  206. case 6:
  207. {if(k==6)
  208. sum1=sum1+450;}
  209. } }
  210.  
  211. case 2:
  212. if(b==2)
  213. {
  214. cout<<"\n CHOOSE YOUR RIDE(1-6)";
  215. cin>>k;
  216. switch(k)
  217. {
  218. case 1:
  219. { if(k==1)
  220. sum1=sum1+400;}
  221. case 2:
  222. {if(k==2)
  223. sum1=sum1+425;}
  224. case 3:
  225. { if(k==3)
  226. sum1=sum1+450;}
  227. case 4:
  228. { if(k==4)
  229. sum1=sum1+475;}
  230. case 5:
  231. { if(k==5)
  232. sum1=sum1+500;}
  233. case 6:
  234. { if(k==6)
  235. sum1=sum+550;}
  236. }
  237. }
  238.  
  239. case 3:
  240. if(b==3)
  241. {
  242. cout<<"\n CHOOSE YOUR RIDE(1-6)";
  243. cin>>k;
  244. switch(k)
  245. {
  246. case 1:
  247. {if(k==1)
  248. sum1=sum1+450;}
  249. case 2:
  250. { if(k==2)
  251. sum1=sum1+475;}
  252. case 3:
  253. { if(k==3)
  254. sum1=sum1+500;}
  255. case 4:
  256. { if(k==4)
  257. sum1=sum1+525;}
  258. case 5:
  259. { if(k==5)
  260. sum1=sum1+550;}
  261. case 6:
  262. { if(k==6)
  263. sum1=sum1+600;}
  264. }
  265. } } }
  266.  
  267. char h;
  268. cout<<"\n DO YOU WANT TO CONTINUE? PRESS Y OR N";
  269. cin>>h;
  270. if(h=='y'||h=='Y')
  271. goto start;
  272.  
  273. else
  274. {
  275. cout<<"\n PRESS 1 TO ENTER FOOD ZONE\n PRESS 2 TO ENTER WATER PARADISE\n PRESS 3 TO EXIT\n";
  276. cin>>r;
  277. if(r==1)
  278. {
  279. starter:
  280. {
  281. cout<<"\n\n\n";
  282. cout<<"  \t\t   SNACK ZONE         \n";
  283. cout<<"\t\t#################################\n\n\n";
  284. cout<<"\t\t1.FRENCH FRIES\t\tRS40/-\n\t\t2.VEG KOTHE\t\t\tRS60/-\n\t\t3.PASTA\t\t\tRS85/-\n\t\t\t4.GRILLED SANDWICH\t\tRS90/-\n\t\t\t5.VEG CUTLET\t\t\tRS50/-\n\t\t6.COFFEE/TEA\t\t\tRS55/-\n\t\t\t7.PIZZA\t\t\tRS150/-\n";
  285. cout<<"\n WHAT WOULD YOU LIKE TO HAVE?";
  286. cout<<"\n ENTER THE CODE TO PLACE YOUR ORDER";
  287. cin>>l;
  288. char t;
  289. cout<<"WOULD YOU LIKE TO PLAY A GAME OF TIC TAC TOE WHILE YOU WAIT FOR YOUR BILL??(Y/N)";
  290. cin>>t;
  291. if((t=='y')||(t=='Y'))
  292. goto tictactoe;
  293. else
  294. {
  295.  summation:
  296. switch(l)
  297. {
  298. case 1:
  299. { if(l==1)
  300. sum2=sum2+40;}
  301. case 2:
  302. { if(l==2)
  303. sum2=sum2+60;}
  304. case 3:
  305. { if(l==3)
  306. sum2=sum2+85;}
  307. case 4:
  308. { if(l==4)
  309. sum2=sum2+90;}
  310. case 5:
  311. { if(l==5)
  312. sum2=sum2+50;}
  313. case 6:
  314. { if(l==6)
  315. sum2=sum2+55;}
  316. case 7:
  317. { if(l==7)
  318. sum2=sum2+150;}
  319. } }
  320.  
  321. char m;
  322. cout<<"\nWANT TO CONTINUE";
  323. cin>>m;
  324. if(m=='y'||m=='Y')
  325. goto starter;
  326. else
  327. { cout<<"\n THANKS FOR VISITING US";
  328. cout<<"\n\nPRESS ANY KEY TO REACH BILLING COUNTER";
  329. getch();
  330.  
  331. bill:
  332. {
  333. clrscr();
  334. cout<<"\n\n\n";
  335. cout<<"\t|-------------------------------------------------|\n";
  336. cout<<"\t|                   BILL                          |\n";
  337. cout<<"\t|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|\n";
  338. cout<<"\t|-----------------------|-------------------------|\n";
  339. cout<<"\t|  CRITERIA             |        TOTAL AMOUNT     |\n";
  340. cout<<"\t|                       |                         |\n";
  341. cout<<"\t|-----------------------|-------------------------|\n";
  342. cout<<"\t|  ENTRY FEES           |"<<setw(6)<<sum<<"       |\n";
  343. cout<<"\t|                       |                         |\n";
  344. cout<<"\t| PRICES FOR RIDES      |"<<setw(6)<<sum1+sum3<< "|\n";
  345. cout<<"\t|                       |                         |\n";
  346. cout<<"\t| PRICES FOR FOOD       |"<<setw(6)<<sum2<<";     |\n";
  347. cout<<"\t|                       |                         |\n";
  348. cout<<"\t|-----------------------|-------------------------|\n";
  349. cout<<"\t|                       |                         |\n";
  350. cout<<"\t| NET PRICE             |"<<setw(6)<<sum+sum1+sum2+sum3<<"|\n";
  351. cout<<"\t|               |                |\n";
  352. cout<<"\t|-------------------|----------------------------------|\n";
  353.  
  354.  
  355. cout<<"\t ####################################################\n";
  356. cout<<"\n\n\n\n";
  357. cout<<"\t       THANKS FOR VISITING \n";
  358. cout<<"\t           HAVE A NICE DAY \n";
  359. cout<<"\n\n\n\n";
  360. cout<<"\t ####################################################\n";
  361.  
  362. getch();
  363. exit(0);
  364. } } }
  365.  
  366. if(r==2)
  367. {
  368. water:
  369. {
  370.  
  371. int s,t;
  372. cout<<"\n\n\n\n";
  373. cout<<"\t\t          WATER PARADISE \n";
  374. cout<<"\t\t ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n";
  375. cout<<"\t\t|---------------------|----------------------|\n";
  376. cout<<"\t\t|   KIDS SLIDES       |   ADULT SLIDES       |\n";
  377. cout<<"\t\t|---------------------|----------------------|\n";
  378. cout<<"\t\t| 1.JUST SLIDES       | 1.WATER OVERLOAD     |\n";
  379. cout<<"\t\t|---------------------|----------------------|\n";
  380. cout<<"\t\t| 2.MAZE OF SLIDES    | 2.DISCO SLIDES       |\n";
  381. cout<<"\t\t|---------------------|----------------------|\n";
  382. cout<<"\t\t| 3.WATER BUCKETS     | 3.CRAZY WATER        |\n";
  383. cout<<"\t\t|---------------------|----------------------|\n";
  384.  
  385. cout<<"\n\t\tENTER CHOICE\n\n\t1.KIDS SLIDES\n\t2.ADULT SLIDES\n";
  386. cin>>s;
  387. switch(s)
  388. {
  389. case 1:
  390. { cout<<"\n CHOOSE YOUR SLIDE(1-3)\n";
  391. cin>>t;
  392. if(t==1)
  393. sum3=sum3+600;
  394. if(t==2)
  395. sum3=sum3+650;
  396. if(t==3)
  397. sum3=sum3+700;
  398. }
  399.  
  400. case 2:
  401. { cout<<"\nCHOOSE YOUR SLIDE(1-3)\n";
  402. cin>>t;
  403. if(t==1)
  404. sum3=sum3+700;
  405. if(t==2)
  406. sum3=sum3+750;
  407. if(t==3)
  408. sum3=sum3+800;
  409. }
  410. getch();}
  411. } } }
  412.  
  413. char u; int v;
  414. cout<<"\nWANT TO CONTINUE?\n";
  415. cin>>u;
  416. if(u=='y'||u=='Y')
  417. goto water;
  418. else
  419. {
  420. cout<<"\nPRESS\n\n\t1.LAND SLIDES\n\t2.FOOD ZONE\n\t3.EXIT\n";
  421. cin>>v;
  422.  switch(v)
  423. {
  424. case 1:
  425. goto start;
  426. case 2:
  427. goto starter;
  428. case 3:
  429. goto bill;
  430. } } }
  431. case 2:
  432. goto water;
  433. }
  434.  
  435. if(r==3)
  436. {cout<<"\n\nPRESS ANY KEY TO REACH BILLING COUNTER";
  437. goto bill;
  438. }
  439. getch();
  440.  //tic tac toe game
  441. tictactoe:
  442. {
  443. int player = 1,z,choice;
  444. char mark;
  445. do{
  446. board();
  447. player=(player%2)?1:2;
  448. cout << "Player " << player << ", enter a number:  ";
  449. cin >> choice;
  450. mark=(player == 1) ? 'X' : 'O';
  451. if (choice == 1 && square[1] == '1')
  452. square[1] = mark;
  453. else if (choice == 2 && square[2] == '2')
  454. square[2] = mark;
  455. else if (choice == 3 && square[3] == '3')
  456. square[3] = mark;
  457. else if (choice == 4 && square[4] == '4')
  458. square[4] = mark;
  459. else if (choice == 5 && square[5] == '5')
  460. square[5] = mark;
  461. else if (choice == 6 && square[6] == '6')
  462. square[6] = mark;
  463. else if (choice == 7 && square[7] == '7')
  464. square[7] = mark;
  465. else if (choice == 8 && square[8] == '8')
  466. square[8] = mark;
  467. else if (choice == 9 && square[9] == '9')
  468. square[9] = mark;
  469. else
  470. {cout<<"Invalid move ";
  471. player--;
  472. cin.ignore();
  473. cin.get();
  474. }
  475. z=checkwin();
  476. player++;
  477. }while(z==-1);
  478. board();
  479. if(z==1)
  480.  
  481. cout<<"==>\aPlayer "<<--player<<" win ";
  482. else
  483. cout<<"==>\aGame draw";
  484. cin.ignore();
  485. cin.get();
  486. goto  summation;
  487. }
  488.  
  489. /*********************************************
  490.  
  491.     FUNCTION TO RETURN GAME STATUS
  492.     1 FOR GAME IS OVER WITH RESULT
  493.     -1 FOR GAME IS IN PROGRESS
  494.     O GAME IS OVER AND NO RESULT
  495. **********************************************/
  496.  
  497. int checkwin()
  498. {
  499.     if (square[1] == square[2] && square[2] == square[3])
  500.  
  501.         return 1;
  502.     else if (square[4] == square[5] && square[5] == square[6])
  503.  
  504.         return 1;
  505.     else if (square[7] == square[8] && square[8] == square[9])
  506.  
  507.         return 1;
  508.     else if (square[1] == square[4] && square[4] == square[7])
  509.  
  510.         return 1;
  511.     else if (square[2] == square[5] && square[5] == square[8])
  512.  
  513.         return 1;
  514.     else if (square[3] == square[6] && square[6] == square[9])
  515.  
  516.         return 1;
  517.     else if (square[1] == square[5] && square[5] == square[9])
  518.  
  519.         return 1;
  520.     else if (square[3] == square[5] && square[5] == square[7])
  521.  
  522.         return 1;
  523.     else if (square[1] != '1' && square[2] != '2' && square[3] != '3'
  524.             && square[4] != '4' && square[5] != '5' && square[6] != '6'
  525.           && square[7] != '7' && square[8] != '8' && square[9] != '9')
  526.  
  527.         return 0;
  528.     else
  529.         return -1;
  530. }
  531.  
  532.  
  533. /*******************************************************************
  534.      FUNCTION TO DRAW BOARD OF TIC TAC TOE WITH PLAYERS MARK
  535. ********************************************************************/
  536.  
  537.  
  538. void board()
  539. {
  540.     clrscr();
  541.     cout << "\n\n\tTic Tac Toe\n\n";
  542.  
  543.     cout << "Player 1 (X)  -  Player 2 (O)" << endl << endl;
  544.     cout << endl;
  545.  
  546.     cout << "     |     |     " << endl;
  547.     cout << "  " << square[1] << "  |  " << square[2] << "  |  " << square[3] << endl;
  548.  
  549.     cout << "_____|_____|_____" <<endl;
  550.     cout << "     |     |     " << endl;
  551.  
  552.     cout << "  " << square[4] << "  |  " << square[5] << "  |  " << square[6] << endl;
  553.  
  554.     cout << "_____|_____|_____" << endl;
  555.     cout << "     |     |     " << endl;
  556.  
  557.     cout << "  " << square[7] << "  |  " << square[8] << "  |  " << square[9] << endl;
  558.  
  559.     cout << "     |     |     " << endl << endl;
  560. };
  561. }}
unreachable code warning is at line 435
declaration syntax error is at line 497 or 498.
Jan 7 '17 #1

✓ answered by weaknessforcats

When you call a function you don't use the return type. Just remove the void inside main();

Share this Question
Share on Google+
5 Replies


weaknessforcats
Expert Mod 5K+
P: 9,197
When you call a function you don't use the return type. Just remove the void inside main();
Jan 7 '17 #2

samrah
P: 3
I'm sorry I didn't get what you told me to do.Can you explain it please?
Jan 14 '17 #3

weaknessforcats
Expert Mod 5K+
P: 9,197
You call a function by:

Expand|Select|Wrap|Line Numbers
  1. pg3();
  2.  
  3.  
and not by:

Expand|Select|Wrap|Line Numbers
  1. void pg3();
void pg3(); is a function prototype. You can't use it for both a prototype and a call. The compiler won't allow it.
Jan 14 '17 #4

samrah
P: 3
void pg3();
is where i am defining the function and
pg3();
is where i'm calling it.
moreover the error is on line 498.
so please help.i've to submit my project in 3 days.
Jan 15 '17 #5

weaknessforcats
Expert Mod 5K+
P: 9,197
I am not able to compile your code from your first post because of problems with mis-matched or missing braces.

You need to compile the code and fix the first error. Then re-compile. Many errors go away when you do this.

Do you have more recent code?
Jan 15 '17 #6

Post your reply

Sign in to post your reply or Sign up for a free account.