Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Catalina Sanabria
- // COP 1000C 03/21/2019
- // Car Race
- #include <stdio.h>
- #include <stdlib.h>
- #include <stdbool.h>
- void newLine2() { printf("\n\n"); }
- int getMax(int a, int b, int c) {
- int max = 0;
- if (max < a)
- max = a;
- if (max < b)
- max = b;
- if (max < c)
- max = c;
- return max;
- }
- int generateSpace() { return 1 + rand() % 3; }
- int moveCar(char letter, int x) {
- for (int i = 0; i < x; i++) {
- printf("%c", letter);
- }
- int randNum = generateSpace();
- for (int i = 0; i < randNum; i++) {
- printf("%c", letter);
- }
- return randNum;
- }
- int main() {
- char A = 'A', B = 'B', C = 'C';
- int a = 0, b = 0, c = 0;
- bool finished = false;
- while (!finished) {
- a += moveCar(A, a);
- newLine2();
- b += moveCar(B, b);
- newLine2();
- c += moveCar(C, c);
- newLine2();
- // system("cls");
- finished = getMax(a, b, c) >= 80;
- }
- // system("PAUSE");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement