Can't get this to compile for some reason. Anyone have an idea what's going on with it?

#include <iostream.h>
#include <stdlib.h>
#include <iomanip.h>
#include <time.h>

void MoveT(int *tortoisePtr, const int End_race);
void MoveHare(int *harePtr, const int End_race);
void PrintCurrentPosition(const int *snapperPtr, const int *bunnyPtr, const int End_race);

int main()
{

const int End_race=70;
int tortoise=1,hare=1,timer=0;




     cout<<"BANG!!!"<<endl;
     cout<<"AND THEY'RE OFF !!!!"<<endl;
     
     srand(time(NULL));
     

while(tortoise != End_race && hare != End_race)
{
     MoveT(&tortoise,End_race);
     MoveHare(&hare,End_race);
     PrintCurrentPosition(&tortoise,&hare,End_race);
     timer++;
}

if(&tortoise>=&hare)
     
     cout<<"tortoise wins: ";

else
     cout<<"hare wins: ";

     cout<<timer<<endl;

return 0;
}





void MoveT(int *tortoisePtr, const int End_race)

{
     int ranNum;

     ranNum = (rand()%10)+1  ;

if(ranNum>=1 && ranNum<=5)

     *tortoisePtr += 3;
 
else if(ranNum == 6 || ranNum == 7)
     *tortoisePtr -= 6;

else
     *tortoisePtr += 1;


if (*tortoisePtr<1)
     *tortoisePtr=1;

else if(*tortoisePtr>End_race)
     *tortoisePtr=End_race;

}





void MoveHare(int *harePtr, const int End_race)          
{
     int hrandNum;

     hrandNum= (rand()%10)+1;
     
if(hrandNum ==3 || hrandNum ==4)
     *harePtr +=9;
     
else if(*harePtr==5)
     *harePtr -=12;

else if(hrandNum>=6 && hrandNum<=8)
     *harePtr +=1;

else if(hrandNum>8)
     *harePtr -=2;

     
if(*harePtr<1)
     *harePtr=1;

else if(*harePtr>End_race)
     *harePtr=End_race;
cout<<endl;
}






void PrintCurrentPosition(const int *snapperPtr, const int *bunnyPtr, const int End_race)
{
if(*snapperPtr == *bunnyPtr) 
     cout<<setw(*bunnyPtr)<<"OUCH!!";
     
else if(*snapperPtr<*bunnyPtr)
{
     cout<<setw(*bunnyPtr)<<'H';
     cout<<setw(*snapperPtr-*bunnyPtr)<<'T';
     
}
else
{
     cout<<setw(*snapperPtr)<<'T'; 
     cout<<setw(*bunnyPtr-*snapperPtr)<<'H'<<endl;
     cout<<endl;
}

}

}

Can't get this to compile for some reason. Anyone have an idea what's going on with it?

Another victim of the "poorly indented code" bug: you have an extra closing } at the end of the file.

comment out one function at a time until you get back to a spot where it does compile. The last item you commented out probably has the error. Once you've found the function that's giving you trouble comment it all out to an empty body and start adding back one line/activity at a time to see what line is the likely culprit. As it stands I see several possible problems, but they should result in run time errors, not prevent compiling. Learning how to debug is as important as learning how to write code in the first place. Good luck.

Okay, I cleaned up the code a bit and am still getting a compile error. Here's the code.

#include <iostream>
#include <stdlib>
#include <iomanip>
#include <time>

void MoveT(int *tortoisePtr, const int End_race);
void MoveHare(int *harePtr, const int End_race);
void PrintCurrentPosition(const int *snapperPtr, const int *bunnyPtr, const int End_race);

int main()
{

const int End_race=70;
int tortoise=1,hare=1,timer=0;

	cout << "BANG!!!" << endl;
    cout << "AND THEY'RE OFF !!!!" << endl;
     
    srand(time(NULL));
     

while(tortoise != End_race && hare != End_race)
	{
     MoveT(&tortoise,End_race);
     MoveHare(&hare,End_race);
     PrintCurrentPosition(&tortoise,&hare,End_race);
     timer++;
	}

if(&tortoise>=&hare)
     cout << "TORTOISE WINS!!! YAY!!!" << endl;

else
     cout << "Hare wins. Yuch." << endl;
	 cout << timer << endl;

return 0;
}





void MoveT(int *tortoisePtr, const int End_race)
{
    int ranNum;
    ranNum = (rand()%10)+1  ;

if(ranNum >= 1 && ranNum <= 5)
	*tortoisePtr += 3;
 
else if(ranNum == 6 || ranNum == 7)
     *tortoisePtr -= 6;

else
     *tortoisePtr += 1;

if (*tortoisePtr<1)
     *tortoisePtr=1;

else if(*tortoisePtr>End_race)
     *tortoisePtr=End_race;
}


void MoveHare(int *harePtr, const int End_race)          
{
	int hrandNum;
	hrandNum= (rand()%10) + 1;
     
if(hrandNum ==3 || hrandNum == 4)
    *harePtr += 9;
     
else if(*harePtr == 5)
    *harePtr -= 12;

else if(hrandNum >= 6 && hrandNum <= 8)
    *harePtr += 1;

else if(hrandNum > 8)
    *harePtr -= 2;

if(*harePtr < 1)
    *harePtr = 1;

else if(*harePtr > End_race)
    *harePtr = End_race;
	cout << endl;
}


void PrintCurrentPosition(const int *snapperPtr, const int *bunnyPtr, const int End_race)
{
if(*snapperPtr == *bunnyPtr) 
     cout << setw(*bunnyPtr) << "OUCH!!";
     
else if(*snapperPtr < *bunnyPtr)
	{
     cout << setw(*bunnyPtr) << 'H';
     cout << setw(*snapperPtr - *bunnyPtr) << 'T';
     }
else
	{
     cout << setw(*snapperPtr) << 'T'; 
     cout << setw(*bunnyPtr-*snapperPtr) << 'H' << endl;
     cout << endl;
	}
}

Add this (for now, until you learn why not to).

#include <time>
using namespace std;

void MoveT(int *tortoisePtr, const int End_race);

change the headers as

#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <ctime>

include the following statement after the include statements

using namespace std;

OR
append

std::

before

cout ,endl, setw

.
For ex.

std::cout <<

Put a

std::cin.ignore(  );

before the return statement.

Add this (for now, until you learn why not to).

#include <time>
using namespace std;

void MoveT(int *tortoisePtr, const int End_race);

I already have all of that code in there.

I already have all of that code in there.

Is that a question?

Taking your last posted code I get errors. Changing the first few lines to this.

#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <ctime>
using namespace std;

And it compiles and runs. This is my output.

BANG!!!
AND THEY'RE OFF !!!!

 TH


  TH


   TH


 HT
 HT
 HT
   TH


 HT
   TH


    TH


     TH


      TH


    OUCH!!
     OUCH!!
           HT
            HT
                     HT
                      HT
                      HT
                      HT
                               HT
                             HT
                             HT
                              HT
                            HT
                                     HT
                                              HT
                                               HT
                                                HT
                                                HT
                                                         HT
                                                                  HT
                                                                HT
                                                                 HT
                                                                  HT
                                                                     HTTORTOISE WINS!!! YAY!!!
36
This article has been dead for over six months. Start a new discussion instead.