ahmed0saber

Math Exam with time in C++

Nov 8th, 2020
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.12 KB | None | 0 0
  1. #include <iostream>
  2. #include <windows.h>
  3. #include <time.h>
  4. #include <conio.h>
  5. using namespace std;
  6. int main()
  7. {
  8. int j=0;
  9.     for (int a=3; a>0 ; a--)
  10.     {
  11.         cout<<"\rGet ready to play in : "<<a;
  12.         Beep(2000,300);Beep(0,700);
  13.     }
  14.     Beep(0,500);
  15.         cout << "\n( YOU HAVE ONLY 5 SECONDS TO SOLVE EACH QUESTION )\n-----------------------------------------------------------------------\n\n";
  16.         Beep(0,4000);
  17.         for ( int i=1; i<=5; i++)
  18.         {
  19.             srand(time(0));
  20.             int A = rand()%10+1+10*(i-1);
  21.             int B = rand()%10+1+10*(i-1);
  22.             cout << " Question " << i << " :     " << A << " + " << B << " = ";
  23.             int numInput;
  24.             time_t start = time(0);
  25.             while ( !kbhit() )
  26.             {
  27.                 if (abs(time(0) - start) > 5)
  28.                 {
  29.                     j=1;
  30.                     break;
  31.                 }
  32.             }
  33.             if (j==1)
  34.             {
  35.                 cout << " Time's Up!!";
  36.                 j=2;
  37.             }
  38.              else
  39.             {
  40.                 cin >> numInput;
  41.                 if ((time(0)-start)>5)
  42.                 {
  43.                     cout << " Time's Up!!";
  44.                     j=2;
  45.                 }
  46.                 else if ( numInput == A+B ) cout << " Good Job!!\n\n";
  47.                 else
  48.                 {
  49.                     cout << " Wrong Answer!!";
  50.                     j=2;
  51.                 }
  52.             }
  53.             if (j==2) break;
  54.         }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment