Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <time.h>
- #include <cstdlib>
- #include <conio.h>
- using namespace std;
- int a, b, c;
- char equ_mark;
- void Intro ()
- {
- printf ("---WELCOME TO MATH GAME---\n\n");
- printf ("* How to play: \n");
- printf ("Press y if the calculation is right, n if wrong. You have 2 seconds.\n\n");
- printf ("press any key to start....");
- }
- void RandomQ ()
- {
- srand (time(NULL));
- a = rand() % 16;
- b = rand() % 16;
- c = rand() % 31;
- int x = rand() % 1;
- if (x == 0) equ_mark = ' ';
- else equ_mark = '-';
- }
- int main ()
- {
- int point = 0;
- bool lose = false;
- Intro();
- fflush (stdin);
- getch();
- while (lose != true)
- {
- double gap;
- RandomQ();
- // display the q
- printf (a, ' ', equ_mark, ' ', b, " = ", c);
- time_t start, end;
- // time counter
- time (&start);
- if (kbhit())
- {
- time (&end);
- char key = tolower (getch());
- gap = difftime (end, start);
- }
- // result check
- if (gap <= 2.0)
- {
- if (equ_mark == ' ')
- {
- 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
- //re: bac nghien cuu r hang ket luan dum tui
- {
- cout << "Right! Time elapsed: " << gap << "seconds" << endl;
- point ;
- }
- else
- {
- printf ("Oops, wrong...you lose.");
- lose = true;
- }
- }
- if (equ_mark == '-')
- {
- if (((a-b == c) && (key == 'y')) || ((a-b != c) && (key == 'n'))) //chua tim hieu bai toan nhung doan la co van de
- //re: hay the, chua tim hieu ma bac da noi nhu 1 vi than
- {
- cout << "Right! Time elapsed: " << gap << "seconds" << endl;
- point ;
- }
- else
- {
- printf ("Oops, wrong...you lose.");
- lose = true;
- }
- }
- }
- else
- {
- cout << "Time elapsed: " << gap << "seconds" << endl;
- printf ("Too slow. You lose");
- lose = true;
- }
- getch();
- system("cls");
- }
- printf ("Your point: ", point);
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment