I know you guys have probably seen a tortoise and hare race like this before but I am trying to do it differently... I am new to C++, the only errors in this are when i call the three methods in the while loop in main, it says identifier not found and i can't figure out why. Thanks a lot if you help me figure this out.
1>c:\users\nick\downloads\tortoisenhare.cpp(33): error C3861: 'moveTort': identifier not found
1>c:\users\nick\downloads\tortoisenhare.cpp(34): error C3861: 'moveHare': identifier not found
1>c:\users\nick\downloads\tortoisenhare.cpp(35): error C3861: 'printRaceLine': identifier not found
// Nick Elliott
// Started on: 2/17/11
#include <cstdlib>
#include <ctime>
#include <iostream>
using namespace std;
int main ()
{
int runCount = 0;
int tortWins = 0;
int hareWins = 0;
int hareWon = 0;
int tortWon = 0;
srand ( time(NULL) );
cout << "The Tortise and the Hare Race!" << endl;
while(tortWins <= 20 || hareWins <=20)
{
cout << "\nBANG !!! AND THEY'RE OFF !!!" << endl;
int tortPos = 1;
int harePos = 1;
int finish = 70;
int tortMove = 0;
int hareMove = 0;
int raceFinished = 0;
while(tortPos <= 70 && harePos <= 70)
{
tortPos = moveTort(tortMove, tortPos, tortWins, tortWon, raceFinished);
harePos = moveHare(hareMove, harePos, hareWins, raceFinished, hareWon);
printRaceLine(harePos, tortPos);
}
}
if(tortWon == 1 && hareWon == 0)
{
cout << "\nTORTISE WINS!!! YAY!!!";
}
else if(hareWon = 1 && tortWon == 0)
{
cout << "Hare wins. Yuch.";
}
else if(hareWon == 1 && tortWon == 1)
{
cout << "It's a tie";
}
cout << "Races Won: " << "Tortise: " << tortWins << " Hare: " << hareWins;
return 0;
}
int moveTort(int tortMove, int tortPos, int tortWins, int tortWon, int raceFinished)
{
tortMove = rand() % 100 + 1;
if(tortMove >= 1 && tortMove <= 25)
{
tortPos = tortPos + 4;
}
else if(tortMove >= 26 && tortMove <= 40)
{
tortPos = tortPos - 2;
}
else if(tortMove >= 41 && tortMove <= 100)
{
tortPos = tortPos + 2;
}
else if(tortPos < 1)
{
tortPos = 1;
}
else if(tortPos >= 70)
{
tortWins++;
raceFinished = 1;
tortWon = 1;
}
return tortPos;
}
int moveHare(int hareMove, int harePos, int hareWins, int raceFinished, int hareWon)
{
hareMove = rand() % 100 + 1;
if(hareMove >= 1 && hareMove <= 30)
{
harePos = harePos + 0;
}
else if(hareMove >= 31 && hareMove <= 45)
{
harePos = harePos + 10;
}
else if(hareMove >= 46 && hareMove <= 65)
{
harePos = harePos - 15;
}
else if(hareMove >= 66 && hareMove <= 75)
{
harePos = harePos + 5;
}
else if(hareMove >= 76 && hareMove <= 100)
{
harePos = harePos - 3;
}
if(harePos < 1)
{
harePos = 1;
}
else if(harePos >= 70)
{
hareWins++;
raceFinished = 1;
hareWon = 1;
}
return harePos;
}
void printRaceLine(int harePos, int tortPos)
{
int count = 1;
while(count <= 70)
{
if(count == harePos)
{
cout << "H";
count++;
}
else if(count == tortPos)
{
cout << "T";
count++;
}
else if(harePos == tortPos)
{
cout << "OUCH!!";
count++;
}
else
cout << "-";
count++;
}
cout << "\n";
}