Advertisement
Guest User

Untitled

a guest
May 30th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1.  
  2. //libraries
  3. #include "stdafx.h"
  4. #include <iostream>
  5. #include <string>
  6. #include <cstdlib>
  7. #include <math.h>
  8. #include <ctime>
  9. #include <windows.h>
  10. #include <vector>
  11.  
  12. using namespace std;
  13.  
  14. void ShowHorse(int horse, int position) {
  15. cout << horse+1 << "|";
  16. for (int i = 0; i < position; i++)
  17. cout << "-";
  18. cout << "H";
  19. for (int i = position + 1; i < 15; i++)
  20. cout << "-";
  21. cout << "|" << endl;
  22. }
  23. int _tmain(int argc, _TCHAR* argv[])
  24. {
  25. int rand1 = 0;
  26. int positions[3];
  27. memset(positions, 0, 3 * sizeof(int));
  28. bool done = false;
  29. srand(time(NULL));
  30. while (!done) {
  31. for (int horse = 0; horse < 3; horse++) {
  32.  
  33. int rand1 = rand() % 100 + 1;
  34. if (rand1 >= 50)
  35. positions[horse]++;
  36. }
  37. // at this point, all the horses positions are updated, now let's draw them!
  38. cout << endl;
  39. for (int horse = 0; horse < 3; horse++) {
  40. ShowHorse(horse, positions[horse]);
  41. }
  42. for (int i = 0; i < 3; i++)
  43. if (positions[i] == 14)
  44. {
  45. cout << "Horse " << i + 1 <<" won!" <<endl;
  46. done = true;
  47. }
  48. }
  49. system("pause");
  50. return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement