Advertisement
Garey

car_test3

Oct 18th, 2017
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.77 KB | None | 0 0
  1. #include <iostream>
  2. #include <windows.h>
  3. #include <iomanip>
  4. #include <random>
  5.  
  6. using namespace std;
  7.  
  8. const double MIN_SALARY = 330.0;
  9.  
  10. bool hasFinished = false;
  11.  
  12. int average_speed = 0;
  13. int rand_frames = 0;
  14.  
  15. void clearScreen();
  16. void movable_car(int speed_kmh, int allowed_speed_kmh);
  17.  
  18. int main() {
  19.     int car_speed = 0;
  20.     int allowed_speed = 0;
  21.     //int sanction = 0;
  22.  
  23.     cout << "Enter speed in km\\h: ";
  24.     cin >> car_speed;
  25.     cout << "Enter allowed speed in km\\h: ";
  26.     cin >> allowed_speed;
  27.  
  28.     system("cls");
  29.     movable_car(car_speed, allowed_speed);
  30.     system("cls");
  31.  
  32.     hasFinished ? cout << "\nThe delivery has finished! | Average driver speed: " << average_speed / rand_frames << "km\\h" :  cout << "The delivery guy crashed!";
  33.  
  34.     return 0;
  35. }
  36.  
  37. void clearScreen()
  38. {
  39.     HANDLE hOut;
  40.     COORD Position;
  41.  
  42.     hOut = GetStdHandle(STD_OUTPUT_HANDLE);
  43.  
  44.     Position.X = 0;
  45.     Position.Y = 0;
  46.     SetConsoleCursorPosition(hOut, Position);
  47. }
  48.  
  49. void movable_car(int speed_kmh, int allowed_speed_kmh) {
  50.  
  51.     CONSOLE_SCREEN_BUFFER_INFO csbi;
  52.     unsigned int frames;
  53.  
  54.     GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
  55.     frames = csbi.srWindow.Right - csbi.srWindow.Left + 1;
  56.     srand (time(NULL));
  57.  
  58.     for (size_t i = 0; i < frames - 1; i++) {
  59.         clearScreen();
  60.  
  61.         int random_int = rand() % (allowed_speed_kmh + speed_kmh);
  62.         average_speed += random_int;
  63.         rand_frames++;
  64.  
  65.         cout << setw(i - 5) << "     .--------." << endl;
  66.         cout << setw(i) << "___/_____|___ \\____" << endl;
  67.         cout << setw(i + 1) << "*    _   - |   _   O" << endl;
  68.         cout << setw(i) << "'--(_)-------(_)--'"  << endl;
  69.         cout << "\n\n" <<"Status: " << (hasFinished ? "Finished | " : "Driving | ") << random_int << "km\\h";
  70.         Sleep(random_int);
  71.     }
  72.  
  73.     hasFinished = !hasFinished;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement