I'm learning C++ and was told to make a horse racing game for class. I've mostly finished it, it prints a horse, and moves it if a random number is over 5, then waits a moment, clears the screen, and repeat. However, whenever I have the system("cls"); added, it completely breaks the program. Can someone figure out what has gone wrong?
code:
#include <iostream>
#include <Windows.h>
#include <stdlib.h>
#include <time.h>
#include <cstdlib>
using namespace std;
void horse(int &p);
int main()
{
srand((unsigned) time(NULL));
int p=0;
do{
system("cls");
horse (p);
Sleep(250);
}while (p<20);
}
void horse (int &p)
{
for (int i;i<20;i++)
if (i==p)
cout<<"#";
else
cout<<"-";
cout<<endl;
if (rand()%11>5)
p++;
}
for clearscreen to clear off my horse, instead it completely breaks my program