Tortoise Hare Race

Ok so I have a code for the race and it works, but I need to add a finish line to the right hand side of the page when it's printed out. How do I do that? Also is there a way I can slow down the rate the T & H are printed out?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#include <iostream>

using std::cout;
using std::endl;

#include <cstdlib>

#include <ctime>

#include <iomanip>

using std::setw;

const int RACE_END = 70;

/* Write prototype for Tortoise here */
void Tortoise (int *);
/* Write prototype for Hare here */
void Hare(int *);
/* Write prototype for positions here */
void positions( int *,int *);

int main()
{
   int T = 1; 
   int H = 1;
   int timer = 0;

   srand( time( 0 ) );

   cout << "ON YOUR MARK, GET SET\nGO!!!!\n";
   
   // controls race
   while ( T != RACE_END && H != RACE_END ) {
      /* call for Tortoise*/
	   Tortoise(&T);
      /* call for Hare */
	   Hare(&H);
      /* call for positions*/
	   positions(&T,&H);
      ++timer;

   } // end while

   // determine winner
   if(T>H){
      cout << "\nTortoise Wins!\n";
   }
   else if(T<H){
	   cout << "\n Hare Wins!\n";
   }
   else if(T=H){
      cout << "It's a tie!\n";
   }
      return 0;

   
} // end main

// move tortoise
/* Write function definition header for Tortoise here */
void Tortoise(int *turtlePtr)
{
   int x = 1 + rand() % 10;

   

   // determine which move to make
   if ( x >= 1 && x <= 5 )        // fast plod
      *turtlePtr += 3;

   else if ( x == 6 || x == 7 )   // slip
      *turtlePtr -= 6;

   else                           // slow plod
      ++( *turtlePtr );
   if ( *turtlePtr < 1 )
      *turtlePtr = 1;

   else if ( *turtlePtr > RACE_END )
      *turtlePtr = RACE_END;

} // end function Tortoise

// move hare
/* Write function definition for Hare here */
void Hare(int *harePtr)
{
   int y = 1 + rand() % 10;

   /* Write statements that move hare */


   // determine which move to make
   if ( y >= 1 && y <= 5 )        // fast plod
      *harePtr += 3;

   else if ( y == 6 || y == 7 )   // slip
      *harePtr -= 6;

   else                           // slow plod
      ++( *harePtr );
   
   
   /* Write statements that test if hare is before
      the starting point or has finished the race */
   if ( *harePtr < 1 )
      *harePtr = 1;

   else if ( *harePtr > RACE_END )
      *harePtr = RACE_END;
} // end function Hare


void positions(int *bunnyPtr,int *snapperPtr)
{
   if ( *bunnyPtr == *snapperPtr ) 
      cout << setw( *bunnyPtr ) << "X!!!";      

   else if ( *bunnyPtr < *snapperPtr ) 
      cout << setw( *bunnyPtr ) << "H" 
           << setw( *snapperPtr - *bunnyPtr ) << "T";

   else
      cout << setw( *snapperPtr ) << "T" 
           << setw( *bunnyPtr - *snapperPtr ) << "H";

   cout << "\n";

} // end function positions 
It might help if you showed us the output you expect in [quote] tags.
well it's going to be quite a few lines and it'll differ each time, an example of one line I have now is

____________T_______________H___________


and what I want it to look like

____________T_______________H___________|


where _ is a space
Ok I got the finish line in there, but how do I delay?
For a delay, you could use #include <windows.h> and then call Sleep(??); with ?? being the milliseconds wanted for a delay. 1000 milliseconds being, of course, 1 second.
Topic archived. No new replies allowed.