Advertisement
Guest User

Untitled

a guest
Mar 24th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. // Catalina Sanabria
  2. // COP 1000C 03/21/2019
  3. // Car Race
  4.  
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <stdbool.h>
  8.  
  9. void newLine2() { printf("\n\n"); }
  10.  
  11. int getMax(int a, int b, int c) {
  12. int max = 0;
  13. if (max < a)
  14. max = a;
  15. if (max < b)
  16. max = b;
  17. if (max < c)
  18. max = c;
  19. return max;
  20. }
  21.  
  22. int generateSpace() { return 1 + rand() % 3; }
  23.  
  24. int moveCar(char letter, int x) {
  25. for (int i = 0; i < x; i++) {
  26. printf("%c", letter);
  27. }
  28. int randNum = generateSpace();
  29. for (int i = 0; i < randNum; i++) {
  30. printf("%c", letter);
  31. }
  32. return randNum;
  33. }
  34.  
  35. int main() {
  36. char A = 'A', B = 'B', C = 'C';
  37. int a = 0, b = 0, c = 0;
  38. bool finished = false;
  39. while (!finished) {
  40. a += moveCar(A, a);
  41. newLine2();
  42. b += moveCar(B, b);
  43. newLine2();
  44. c += moveCar(C, c);
  45. newLine2();
  46. // system("cls");
  47. finished = getMax(a, b, c) >= 80;
  48. }
  49. // system("PAUSE");
  50. return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement