Пожалуйста, расскажите мне сухой прогон этого кода в комментариях
#include <iostream> #include <ctime> #include <windows.h> #include <stdlib.h> using namespace std; int FINISH; void drawhorses(int * Horses,int m) { int a=0; for (int i = 0; i <=m; i++) { if (i % 2 == 1) { cout << "[" << a << "]"; ++a; for (int k = Horses[i]; k < FINISH; k++) { cout << " | "; } for (int k = 0; k < Horses[i]; k++) { cout << " "; } cout << endl; } else { for (int k = 0; k <= FINISH; k++) { cout << " | "; } cout << endl; } } } void draw(int * Horses, int m) { int b = 0; system("cls"); for (int i = 0; i<=m; i++) { if (i % 2 == 1) { for (int k = Horses[i]; k>0; k--) { cout << " "; } cout << "[" << b << "]"; ++b; for (int k = Horses[i]; k < FINISH; k++) { cout << " | "; } cout << endl; } else { for (int k = 0; k <= FINISH; k++) { cout << " | "; } cout << endl; } } } int main() { int Nohorses,n=0; cout << "Enter the number of horses: "; cin >> Nohorses; system("cls"); int dist; cout << "Enter the distance in forlong form 6 to 12: "; cin >> dist; FINISH = dist * 3; n = Nohorses * 2; system("cls"); int *ptr; ptr = new int[n]; srand(time(NULL)); for (int i = 0; i<n; i++) { ptr[i] = 0; } drawhorses(ptr, n); int x = 0; bool end = false; while (!end) { Sleep(800); system("cls"); for (int i = 0; i<n; i++) { x = i; ptr[i] += rand() % 2; if (ptr[i] >= FINISH) { end = true; } } cout << "\n\n"; draw(ptr, n); } delete ptr; system("cls"); cout << "Horse number " << x/2 << " Won the race" << endl; system("pause"); return 0; }
Что я уже пробовал:
#include <iostream> #include <ctime> #include <windows.h> #include <stdlib.h> using namespace std; int FINISH; void drawhorses(int * Horses,int m) { int a=0; for (int i = 0; i <=m; i++) { if (i % 2 == 1) { cout << "[" << a << "]"; ++a; for (int k = Horses[i]; k < FINISH; k++) { cout << " | "; } for (int k = 0; k < Horses[i]; k++) { cout << " "; } cout << endl; } else { for (int k = 0; k <= FINISH; k++) { cout << " | "; } cout << endl; } } } void draw(int * Horses, int m) { int b = 0; system("cls"); for (int i = 0; i<=m; i++) { if (i % 2 == 1) { for (int k = Horses[i]; k>0; k--) { cout << " "; } cout << "[" << b << "]"; ++b; for (int k = Horses[i]; k < FINISH; k++) { cout << " | "; } cout << endl; } else { for (int k = 0; k <= FINISH; k++) { cout << " | "; } cout << endl; } } } int main() { int Nohorses,n=0; cout << "Enter the number of horses: "; cin >> Nohorses; system("cls"); int dist; cout << "Enter the distance in forlong form 6 to 12: "; cin >> dist; FINISH = dist * 3; n = Nohorses * 2; system("cls"); int *ptr; ptr = new int[n]; srand(time(NULL)); for (int i = 0; i<n; i++) { ptr[i] = 0; } drawhorses(ptr, n); int x = 0; bool end = false; while (!end) { Sleep(800); system("cls"); for (int i = 0; i<n; i++) { x = i; ptr[i] += rand() % 2; if (ptr[i] >= FINISH) { end = true; } } cout << "\n\n"; draw(ptr, n); } delete ptr; system("cls"); cout << "Horse number " << x/2 << " Won the race" << endl; system("pause"); return 0; }