Keita2910

Freaking Math <simplified> by I.K

Mar 25th, 2017
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.71 KB | None | 0 0
  1. #include <iostream>
  2. #include <time.h>
  3. #include <cstdlib>
  4. #include <conio.h>
  5. using namespace std;
  6.  
  7. int a, b, c;
  8. char equ_mark;
  9.  
  10. void Intro ()
  11. {
  12. printf ("---WELCOME TO MATH GAME---\n\n");
  13. printf ("* How to play: \n");
  14. printf ("Press y if the calculation is right, n if wrong. You have 2 seconds.\n\n");
  15. printf ("press any key to start....");
  16. }
  17.  
  18. void RandomQ ()
  19. {
  20. srand (time(NULL));
  21. a = rand() % 16;
  22. b = rand() % 16;
  23. c = rand() % 31;
  24. int x = rand() % 1;
  25. if (x == 0) equ_mark = ' ';
  26. else equ_mark = '-';
  27. }
  28.  
  29. int main ()
  30. {
  31. int point = 0;
  32. bool lose = false;
  33.  
  34. Intro();
  35.  
  36. fflush (stdin);
  37. getch();
  38.  
  39. while (lose != true)
  40. {
  41. double gap;
  42.  
  43. RandomQ();
  44. // display the q
  45. printf (a, ' ', equ_mark, ' ', b, " = ", c);
  46.  
  47. time_t start, end;
  48. // time counter
  49. time (&start);
  50. if (kbhit())
  51. {
  52. time (&end);
  53. char key = tolower (getch());
  54. gap = difftime (end, start);
  55. }
  56.  
  57. // result check
  58. if (gap <= 2.0)
  59. {
  60. if (equ_mark == ' ')
  61. {
  62. if (((a b == c) && (key == 'y')) || ((a b != c) && (key == 'n'))) // phong doan dieu kien nay co van de , chua nghien cuu ki nhung doan se co van de
  63. //re: bac nghien cuu r hang ket luan dum tui
  64. {
  65. cout << "Right! Time elapsed: " << gap << "seconds" << endl;
  66. point  ;
  67. }
  68. else
  69. {
  70. printf ("Oops, wrong...you lose.");
  71. lose = true;
  72. }
  73. }
  74.  
  75. if (equ_mark == '-')
  76. {
  77. if (((a-b == c) && (key == 'y')) || ((a-b != c) && (key == 'n'))) //chua tim hieu bai toan nhung doan la co van de
  78. //re: hay the, chua tim hieu ma bac da noi nhu 1 vi than
  79. {
  80. cout << "Right! Time elapsed: " << gap << "seconds" << endl;
  81. point  ;
  82. }
  83. else
  84. {
  85. printf ("Oops, wrong...you lose.");
  86. lose = true;
  87. }
  88. }
  89. }
  90.  
  91. else
  92. {
  93. cout << "Time elapsed: " << gap << "seconds" << endl;
  94. printf ("Too slow. You lose");
  95. lose = true;
  96. }
  97.  
  98. getch();
  99. system("cls");
  100. }
  101.  
  102. printf ("Your point: ", point);
  103. system("pause");
  104. }
Advertisement
Add Comment
Please, Sign In to add comment