Advertisement
Guest User

lab game

a guest
Jan 28th, 2020
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.83 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. int main()
  4. {
  5. printf("1. Play game?\n");
  6. printf("2. Exit.\n");
  7. int x,p=0;
  8. int ara[6];
  9. scanf("%d", &x);
  10. if(x==2)
  11. {
  12. return 0;
  13. }
  14. else if(x==1)
  15. {
  16. int i;
  17. srand(time(0));
  18.  
  19. for(i=0; i<6; i++)
  20. {
  21. ara[i]=rand()%100;
  22. }
  23.  
  24. printf("First pair of numbers: ");
  25.  
  26. for(i=0; i<2; i++)
  27. {
  28. printf(" %d ",ara[i]);
  29. }
  30. printf("\nPress any key to proceed to the next pair...");
  31. getch();
  32. printf("\nSecond pair of numbers: ");
  33. for(i=2; i<4; i++)
  34. {
  35. printf(" %d ",ara[i]);
  36. }
  37. printf("\nPress any key to proceed to the next pair...");
  38. getch();
  39. printf("\nThird pair of numbers: ");
  40. for(i=4; i<6; i++)
  41. {
  42. printf(" %d ",ara[i]);
  43. }
  44. printf("\nPress any key to proceed to the questions...");
  45. for(p=0; p<3; p++)
  46. {
  47.  
  48.  
  49. printf("\nWhat were the first numbers? 18 90 34 %d 990 %d", ara[1], ara[0]);
  50. printf("\nAnswer: ");
  51. int a,b;
  52. scanf("%d %d",&a,&b);
  53. p=0;
  54. if((a==ara[0]|| a==ara[1])&&(b==ara[0]|| b==ara[1]))
  55. {
  56.  
  57. printf("\nCorrect!!!");
  58. p++;
  59. }
  60. else
  61. {
  62. printf("\nWrong Answer! Start from the first question!");
  63. p=0;
  64. }
  65.  
  66. if(p==1)
  67. {
  68. printf("\nWhat were the second numbers? 28 39 %d 43 70 %d", ara[3], ara[2]);
  69. printf("\nAnswer: ");
  70. int c,d;
  71. scanf("%d %d",&c,&d);
  72. if((c==ara[2]|| c==ara[3])&&(d==ara[3]|| d==ara[2]))
  73. {
  74. p++;
  75. printf("\nCorrect!!!");
  76. }
  77. else
  78. {
  79. printf("\nWrong Answer! Start from the first question!");
  80. p=0;
  81. }
  82.  
  83.  
  84. }
  85.  
  86. if(p==2)
  87. {
  88.  
  89.  
  90. printf("\nWhat were the third numbers? 68 79 %d 34 19 %d", ara[4], ara[5]);
  91. printf("\nAnswer: ");
  92. int e,f;
  93. scanf("%d %d",&e,&f);
  94. if((e==ara[4]|| e==ara[5])&&(f==ara[4]|| f==ara[5]))
  95. {
  96. p++;
  97. printf("\nCorrect!!!");
  98. }
  99. else
  100. {
  101. printf("\nWrong Answer! Start from the first question!");
  102. p=0;
  103. }
  104. }
  105. }
  106. printf("\nCongratulations! You won! Want to play again?");
  107. printf("\n1. Play Game?");
  108. printf("\n2. Exit");
  109.  
  110.  
  111. }
  112.  
  113.  
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement