I'm just beginning to create the infamous tortoise and hare project, but cannot get my code to print out the correct corresponding numbers. Any ideas?
Code:
#include <iostream>
#include <cstdlib> // contains prototypes for functions srand and rand
#include <ctime> // contains prototype for function time
using namespace std;
int troll( void );
int hroll( void );
int main()
{
srand( time( 0 ) );
int t = 0;
int h = 0;
cout << "turtle: " << troll() << endl;
cout << "hare: " << hroll() << endl;
if ( troll() >= 8 )
( t = 1 );
else if ( troll() >= 6 )
( t = -6 );
else if ( troll() <= 5 )
( t = 3 );
else if ( hroll() >= 9 )
( h = 2 );
else if ( hroll() >= 6 )
( h = 1 );
else if ( hroll() == 5 )
( h = 12 );
else if ( hroll() >= 3 )
( h = 9 );
else if ( hroll() >= 1 )
( h = 0 );
else if ( h < 1 )
h = 0;
else if ( t < 1 )
t = 0;
cout << "t: " << t << endl;
cout << "h: " << h << endl;
return 0;
} // end main
// roll movement of tortoise and hare
int troll( void ) {
int troll = 0;
troll = ( 1 + rand() % 10 ); // pick random number between 1 and 10
return troll;
} // end function troll
int hroll( void ) {
int hroll = 0;
hroll = ( 1 + rand() % 10 ); // pick a random number between 1 and 10
return hroll;
} // end function hroll