fork download
  1. #include <iostream>
  2.  
  3.  
  4. #include <string>
  5.  
  6.  
  7. #include <ctime>
  8.  
  9.  
  10. #include <cstdlib>
  11.  
  12.  
  13. #include <time.h>
  14.  
  15.  
  16. using namespace std;
  17.  
  18.  
  19. int Rselect();
  20.  
  21.  
  22. void Obstacle_description (int Ran_num);
  23.  
  24.  
  25. int repeat1 (int& dc, int& lifepoint, int& time);
  26.  
  27.  
  28. void Lifepoints(int& lifepoint);
  29.  
  30.  
  31.  
  32.  
  33. int main()
  34.  
  35.  
  36. { int i=0;
  37.  
  38.  
  39.  
  40. do{
  41.  
  42.  
  43.  
  44. int lifepoint=10;
  45.  
  46. srand(time(0));
  47.  
  48. string choice;
  49.  
  50. i++;
  51.  
  52. cout<<"welcome to pitfall adventure! can you overcome ten
  53. dangerous jungle obstacle in 30 minutes? Let's start and find out!\n";
  54.  
  55. int x=rand()%6+1;
  56.  
  57. int dc=3*x;
  58.  
  59. int time=30;
  60.  
  61. int Ran_num;
  62.  
  63.  
  64.  
  65. Ran_num=Rselect();
  66.  
  67. cout<<"Time="<<time<<" minutes\n";
  68.  
  69. Obstacle_description (Ran_num); //function obstacle
  70.  
  71.  
  72.  
  73. if(dc<=7) cout<<"it looks easy"<<". ";
  74.  
  75. else if (dc>=14) cout<<"it looks hard"<<". ";
  76.  
  77.  
  78.  
  79. cout<<"Do you <rush> or <study> it and then try it?";
  80.  
  81.  
  82.  
  83. cin>>choice;
  84.  
  85.  
  86.  
  87. if(choice=="rush") {time-=2;
  88.  
  89. dc+=2;
  90.  
  91. repeat1 (dc,lifepoint,time);
  92.  
  93. cout<<time;
  94.  
  95. }
  96.  
  97.  
  98.  
  99. else if(choice =="study")
  100.  
  101. {time-=5;
  102.  
  103. dc-=5;
  104.  
  105. repeat1 (dc,lifepoint,time);
  106.  
  107. cout<<time; }
  108.  
  109. cout<<"better next time";
  110.  
  111. }while(time>0 && i < 10);
  112.  
  113. cout<<"win";
  114.  
  115. return 0;
  116.  
  117.  
  118.  
  119. }
  120.  
  121.  
  122.  
  123.  
  124. // slect random number between 0 to 10 that is never smae number to show up
  125.  
  126.  
  127. int Rselect()
  128.  
  129.  
  130. {
  131.  
  132. int i=1,Pnum=-1, Nnum=-1;
  133.  
  134. for(i=1; i<=10; i++)
  135.  
  136. {Nnum = rand()%10+1;
  137.  
  138. while(Nnum==Pnum)
  139.  
  140. Nnum = rand()%10+1;}
  141.  
  142. Pnum=Nnum;
  143.  
  144. return Nnum;
  145.  
  146. }
  147.  
  148.  
  149. //fuction that dc comepared with number(ramdomly variable b/w 1 and 20)
  150.  
  151.  
  152. int repeat1 (int& dc, int& lifepoint, int&time)
  153.  
  154.  
  155. { string choose;
  156.  
  157.  
  158.  
  159. int w;
  160.  
  161.  
  162.  
  163. do {
  164.  
  165.  
  166.  
  167. cout<<"fail!";
  168.  
  169. Lifepoints(lifepoint);
  170.  
  171. cout<<"Do you <rush> or <study> it and then try it?";
  172.  
  173.  
  174.  
  175. cin>>choose;
  176.  
  177.  
  178.  
  179. if(choose=="rush") {time-=2;
  180.  
  181. dc+=2;
  182.  
  183. return time;}
  184.  
  185. else if(choose=="study") {time-=5;
  186.  
  187. dc-=5;
  188.  
  189. cout<<time;}
  190.  
  191.  
  192.  
  193.  
  194.  
  195. w = rand()%20+1;
  196.  
  197. }while (w<dc);
  198.  
  199.  
  200.  
  201. cout<<"success!";
  202.  
  203.  
  204.  
  205. return Rselect();
  206.  
  207.  
  208.  
  209. }
  210.  
  211.  
  212.  
  213. //function of obstacle
  214.  
  215.  
  216.  
  217. void Obstacle_description (int Ran_num)
  218.  
  219.  
  220.  
  221. { string obstacle;
  222.  
  223.  
  224.  
  225. if (Ran_num==1) {obstacle = "you encounter a nasty looking
  226. pit. it's not very deep, but it has wooden spikes at the bottom.
  227. you'll have to jump it to continue.";
  228.  
  229. cout<<"\n"<<"Obstacle: "<<obstacle;}
  230.  
  231.  
  232.  
  233. else if (Ran_num==2) {obstacle = "Before you is a wide river.
  234. is it deep or not? hard to tell! you'll have to swim it.";
  235. cout<<"Obstacle: "<<obstacle<<"\n";}
  236.  
  237.  
  238.  
  239. else if (Ran_num==3) {obstacle = "There is big a hedge. you'll
  240. have to climb over the hedge.";
  241.  
  242. cout<<"Obstacle: "<<obstacle<<"\n";}
  243.  
  244.  
  245.  
  246. else if (Ran_num==4) {obstacle = "you can see a big tree
  247. there. you'll have to climb the big tree.";
  248.  
  249. cout<<"Obstacle: "<<obstacle<<"\n";}
  250.  
  251.  
  252.  
  253. else if (Ran_num==5) {obstacle = "It looks like a narrow pond.
  254. you'll have to jump";
  255.  
  256. cout<<"Obstacle: "<<obstacle<<"\n";}
  257.  
  258.  
  259.  
  260. else if (Ran_num==6) {obstacle = "There is a small gorge
  261. you'll have to jump";
  262.  
  263. cout<<"Obstacle: "<<obstacle<<"\n";}
  264.  
  265.  
  266.  
  267. else if (Ran_num==7) {obstacle = "you can see a Tiger you'll
  268. have to avoid the tiger";
  269.  
  270. cout<<"Obstacle: "<<obstacle<<"\n";}
  271.  
  272.  
  273.  
  274. else if (Ran_num==8) {obstacle = "There is a mud. you'll have to jump";
  275.  
  276. cout<<"Obstacle: "<<obstacle<<"\n";}
  277.  
  278.  
  279.  
  280. else if (Ran_num==9) {obstacle = "It looks like a lion. you'll
  281. have to avoid the lion";
  282.  
  283. cout<<"Obstacle: "<<obstacle<<"\n";}
  284.  
  285.  
  286.  
  287. else if (Ran_num==10) {obstacle = "There is Myrsinaleaf oak in
  288. front of you. you'll have to jump the that"; cout<<"Obstacle:
  289. "<<obstacle<<"\n";}
  290.  
  291.  
  292.  
  293. return ;
  294.  
  295.  
  296.  
  297. }
  298.  
  299.  
  300.  
  301.  
  302.  
  303. //function of life point
  304.  
  305.  
  306.  
  307. void Lifepoints(int& lifepoint)
  308.  
  309.  
  310.  
  311. { int z= rand()%4;
  312.  
  313. if(lifepoint>0)
  314.  
  315. { if (z==0) { cout<<"life is "<<" minor scratches,no harm";
  316.  
  317. lifepoint=lifepoint-z;}
  318.  
  319.  
  320.  
  321. else if (z==1) {cout<<"life is "<<" minor damage";
  322.  
  323. lifepoint=lifepoint-z;}
  324.  
  325. else if (z==2) {cout<<"life is "<<" moderate damage";
  326.  
  327. lifepoint=lifepoint-z;}
  328.  
  329. else if (z==3) {cout<<"life is "<<"major damage";
  330.  
  331. lifepoint=lifepoint-z;}
  332.  
  333. return;
  334.  
  335. }
  336.  
  337.  
  338.  
  339. else if (lifepoint<=0) {
  340.  
  341. cout<<"game end\n";
  342.  
  343. return;
  344.  
  345. }
  346.  
  347. }
  348.  
  349.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:52:15: warning: missing terminating " character [enabled by default]
         cout<<"welcome to pitfall adventure! can you overcome ten
               ^
prog.cpp:52:9: error: missing terminating " character
         cout<<"welcome to pitfall adventure! can you overcome ten
         ^
prog.cpp:53:45: warning: missing terminating ' character [enabled by default]
 dangerous jungle obstacle in 30 minutes? Let's start and find out!\n";
                                             ^
prog.cpp:53:1: error: missing terminating ' character
 dangerous jungle obstacle in 30 minutes? Let's start and find out!\n";
 ^
prog.cpp:225:37: warning: missing terminating " character [enabled by default]
         if (Ran_num==1) {obstacle = "you encounter a nasty looking
                                     ^
prog.cpp:225:9: error: missing terminating " character
         if (Ran_num==1) {obstacle = "you encounter a nasty looking
         ^
prog.cpp:226:8: warning: missing terminating ' character [enabled by default]
 pit. it's not very deep, but it has wooden spikes at the bottom.
        ^
prog.cpp:226:1: error: missing terminating ' character
 pit. it's not very deep, but it has wooden spikes at the bottom.
 ^
prog.cpp:227:4: warning: missing terminating ' character [enabled by default]
 you'll have to jump it to continue.";
    ^
prog.cpp:227:1: error: missing terminating ' character
 you'll have to jump it to continue.";
 ^
prog.cpp:233:42: warning: missing terminating " character [enabled by default]
         else if (Ran_num==2) {obstacle = "Before you is a wide river.
                                          ^
prog.cpp:233:9: error: missing terminating " character
         else if (Ran_num==2) {obstacle = "Before you is a wide river.
         ^
prog.cpp:234:37: warning: missing terminating ' character [enabled by default]
 is it deep or not? hard to tell! you'll have to swim it.";
                                     ^
prog.cpp:234:1: error: missing terminating ' character
 is it deep or not? hard to tell! you'll have to swim it.";
 ^
prog.cpp:239:42: warning: missing terminating " character [enabled by default]
         else if (Ran_num==3) {obstacle = "There is big a hedge. you'll
                                          ^
prog.cpp:239:9: error: missing terminating " character
         else if (Ran_num==3) {obstacle = "There is big a hedge. you'll
         ^
prog.cpp:240:30: warning: missing terminating " character [enabled by default]
 have to climb over the hedge.";
                              ^
prog.cpp:240:1: error: missing terminating " character
 have to climb over the hedge.";
 ^
prog.cpp:246:42: warning: missing terminating " character [enabled by default]
         else if (Ran_num==4) {obstacle = "you can see a big tree
                                          ^
prog.cpp:246:9: error: missing terminating " character
         else if (Ran_num==4) {obstacle = "you can see a big tree
         ^
prog.cpp:247:11: warning: missing terminating ' character [enabled by default]
 there. you'll have to climb the big tree.";
           ^
prog.cpp:247:1: error: missing terminating ' character
 there. you'll have to climb the big tree.";
 ^
prog.cpp:253:42: warning: missing terminating " character [enabled by default]
         else if (Ran_num==5) {obstacle = "It looks like a narrow pond.
                                          ^
prog.cpp:253:9: error: missing terminating " character
         else if (Ran_num==5) {obstacle = "It looks like a narrow pond.
         ^
prog.cpp:254:4: warning: missing terminating ' character [enabled by default]
 you'll have to jump";
    ^
prog.cpp:254:1: error: missing terminating ' character
 you'll have to jump";
 ^
prog.cpp:260:42: warning: missing terminating " character [enabled by default]
         else if (Ran_num==6) {obstacle = "There is a small gorge
                                          ^
prog.cpp:260:9: error: missing terminating " character
         else if (Ran_num==6) {obstacle = "There is a small gorge
         ^
prog.cpp:261:4: warning: missing terminating ' character [enabled by default]
 you'll have to jump";
    ^
prog.cpp:261:1: error: missing terminating ' character
 you'll have to jump";
 ^
prog.cpp:267:42: warning: missing terminating " character [enabled by default]
         else if (Ran_num==7) {obstacle = "you can see a Tiger you'll
                                          ^
prog.cpp:267:9: error: missing terminating " character
         else if (Ran_num==7) {obstacle = "you can see a Tiger you'll
         ^
prog.cpp:268:24: warning: missing terminating " character [enabled by default]
 have to avoid the tiger";
                        ^
prog.cpp:268:1: error: missing terminating " character
 have to avoid the tiger";
 ^
prog.cpp:280:42: warning: missing terminating " character [enabled by default]
         else if (Ran_num==9) {obstacle = "It looks like a lion. you'll
                                          ^
prog.cpp:280:9: error: missing terminating " character
         else if (Ran_num==9) {obstacle = "It looks like a lion. you'll
         ^
prog.cpp:281:23: warning: missing terminating " character [enabled by default]
 have to avoid the lion";
                       ^
prog.cpp:281:1: error: missing terminating " character
 have to avoid the lion";
 ^
prog.cpp:287:43: warning: missing terminating " character [enabled by default]
         else if (Ran_num==10) {obstacle = "There is Myrsinaleaf oak in
                                           ^
prog.cpp:287:9: error: missing terminating " character
         else if (Ran_num==10) {obstacle = "There is Myrsinaleaf oak in
         ^
prog.cpp:288:18: warning: missing terminating ' character [enabled by default]
 front of you. you'll have to jump the that"; cout<<"Obstacle:
                  ^
prog.cpp:288:1: error: missing terminating ' character
 front of you. you'll have to jump the that"; cout<<"Obstacle:
 ^
prog.cpp:289:1: error: stray ‘\’ in program
 "<<obstacle<<"\n";}
 ^
prog.cpp:289:17: warning: missing terminating " character [enabled by default]
 "<<obstacle<<"\n";}
                 ^
prog.cpp:289:1: error: missing terminating " character
 "<<obstacle<<"\n";}
 ^
prog.cpp: In function ‘int main()’:
prog.cpp:53:1: error: ‘dangerous’ was not declared in this scope
 dangerous jungle obstacle in 30 minutes? Let's start and find out!\n";
 ^
prog.cpp:53:11: error: expected ‘;’ before ‘jungle’
 dangerous jungle obstacle in 30 minutes? Let's start and find out!\n";
           ^
prog.cpp:57:18: error: ‘x’ was not declared in this scope
         int dc=3*x;
                  ^
prog.cpp: In function ‘void Obstacle_description(int)’:
prog.cpp:226:1: error: ‘pit’ was not declared in this scope
 pit. it's not very deep, but it has wooden spikes at the bottom.
 ^
prog.cpp:227:1: error: expected ‘;’ before ‘you’
 you'll have to jump it to continue.";
 ^
prog.cpp:234:1: error: ‘is’ was not declared in this scope
 is it deep or not? hard to tell! you'll have to swim it.";
 ^
prog.cpp:234:4: error: expected ‘;’ before ‘it’
 is it deep or not? hard to tell! you'll have to swim it.";
    ^
prog.cpp:240:1: error: ‘have’ was not declared in this scope
 have to climb over the hedge.";
 ^
prog.cpp:240:6: error: expected ‘;’ before ‘to’
 have to climb over the hedge.";
      ^
prog.cpp:247:1: error: ‘there’ was not declared in this scope
 there. you'll have to climb the big tree.";
 ^
prog.cpp:249:13: error: expected ‘;’ before ‘cout’
             cout<<"Obstacle: "<<obstacle<<"\n";}
             ^
prog.cpp:254:1: error: ‘you’ was not declared in this scope
 you'll have to jump";
 ^
prog.cpp:256:13: error: expected ‘;’ before ‘cout’
             cout<<"Obstacle: "<<obstacle<<"\n";}
             ^
prog.cpp:261:1: error: ‘you’ was not declared in this scope
 you'll have to jump";
 ^
prog.cpp:263:13: error: expected ‘;’ before ‘cout’
             cout<<"Obstacle: "<<obstacle<<"\n";}
             ^
prog.cpp:268:1: error: ‘have’ was not declared in this scope
 have to avoid the tiger";
 ^
prog.cpp:268:6: error: expected ‘;’ before ‘to’
 have to avoid the tiger";
      ^
prog.cpp:281:1: error: ‘have’ was not declared in this scope
 have to avoid the lion";
 ^
prog.cpp:281:6: error: expected ‘;’ before ‘to’
 have to avoid the lion";
      ^
prog.cpp:288:1: error: ‘front’ was not declared in this scope
 front of you. you'll have to jump the that"; cout<<"Obstacle:
 ^
prog.cpp:288:7: error: expected ‘;’ before ‘of’
 front of you. you'll have to jump the that"; cout<<"Obstacle:
       ^
prog.cpp:311:5: error: a function-definition is not allowed here before ‘{’ token
     {   int z= rand()%4;
     ^
prog.cpp:347:5: error: expected ‘}’ at end of input
     }
     ^
stdout
Standard output is empty