Advertisement
Garey

Car Emit Sound

Oct 18th, 2017
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.95 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.     PlaySound(" rado.wav", NULL, SND_ASYNC);
  30.     movable_car(car_speed, allowed_speed);
  31.     system("cls");
  32.  
  33.     int minutes = average_speed / 60;
  34.     int hours = minutes / 60;
  35.  
  36.     hasFinished ? cout << "The delivery has finished! | Average driver speed: " << average_speed / rand_frames << "km\\h" << " | Delivery Time: " << (int)hours << " hours and " << minutes << " minutes":  cout << "The delivery guy crashed!";
  37.  
  38.     return 0;
  39. }
  40.  
  41. void clearScreen()
  42. {
  43.     HANDLE hOut;
  44.     COORD Position;
  45.  
  46.     hOut = GetStdHandle(STD_OUTPUT_HANDLE);
  47.  
  48.     Position.X = 0;
  49.     Position.Y = 0;
  50.     SetConsoleCursorPosition(hOut, Position);
  51. }
  52.  
  53. void movable_car(int speed_kmh, int allowed_speed_kmh) {
  54.  
  55.     CONSOLE_SCREEN_BUFFER_INFO csbi;
  56.     unsigned int frames;
  57.  
  58.     GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
  59.     frames = csbi.srWindow.Right - csbi.srWindow.Left + 1;
  60.     srand (time(NULL));
  61.  
  62.     for (size_t i = 0; i < frames - 1; i++) {
  63.         clearScreen();
  64.  
  65.         int random_int = rand() % (allowed_speed_kmh + speed_kmh);
  66.         average_speed += random_int;
  67.         rand_frames++;
  68.  
  69.         cout << setw(i - 5) << "     .--------." << endl;
  70.         cout << setw(i) << "___/_____|___ \\____" << endl;
  71.         cout << setw(i + 1) << "*    _   - |   _   O" << endl;
  72.         cout << setw(i) << "'--(_)-------(_)--'"  << endl;
  73.         cout << "\n\n" <<"Status: " << (hasFinished ? "Finished | " : "Driving | ") << random_int << "km\\h";
  74.         Sleep(random_int);
  75.     }
  76.  
  77.     hasFinished = !hasFinished;
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement