I wrote this code to re-create the classic race of the tortoise and the hare and everything compiles fine. Just the logic is messed up. When I run the program all I see is BANG AND THEY'RE OFF and who wins. I should be seeing a T for the Tortoise and and H for the Hare going across the screen. Can anyone tell me what I am doing wrong.
#include <iostream>
#include <cstdlib>
int main()
{
int i = 0;
int j = 0;
int check;
int check_1;
char play_again = '\n' ;
int tortoise[70];
int hare[70];
cout << "BANG !!!!!\n"
"AND THEY'RE OFF !!!!!" << endl;
while(play_again == '\n')
{
while(i <= 69 && j <= 69)
{
tortoise[i] = 0;;
check = random_1();
if(check == 1 || check == 2 || check == 3 || check == 4 || check ==
5)
tortoise[i+=3] = 0;
if(check == 6 || check == 7)
tortoise[i-=6] = 0;
if(check == 8 || check == 9 || check == 10)
tortoise[i+=1] = 0;
char *ptr;
char line[71] = "----------------------------------------------------------------------";
ptr = line;
if(i < 0){
i = 0;
*(ptr + i) = 'T';}
*(ptr + i) = 'T';
hare[j] = 0;
check_1 = random_1();
if(check_1 == 1 || check_1 == 2)
hare[j] = 0;
if(check_1 == 3 || check_1 == 4)
hare[j+=9] = 0;
if(check_1 == 5)
hare[j+=12] = 0;
if(check_1 == 6 || check_1 == 7 || check_1 == 8)
hare[j++] = 0;
if(check_1 == 9 || check_1 == 10)
hare[j-=2] = 0;
if(j < 0){
j = 0;
*(ptr + j) = 'H';}
*(ptr + j) = 'H';
if(i == j){
*(ptr + i) = 'O';
*(ptr + i + 1) = 'U';
*(ptr + i + 2) = 'C';
*(ptr + i + 3) = 'H';}
break;
}
if(i >= 69)
{
cout << "TORTOISE WINS!!! YAY!!!\n" << endl;
break;
}
if(j >= 69)
{
cout <<"HARE WINS. YUCH.\n" << endl;
break;
}
if(j >= 69 && i >= 69)
{
cout << "IT'S A TIE\n";
break;
}
}
return 0;
}
int random_1()
{
srand(time(NULL));
return (1 + rand() % 10);
}