Random Number for moving Target

Hi all I ran into a problem with my program, Its a golfing program that calls from a sub program. That part of it works but I have to add a moving target and when it gets within 10 feet it should tell me BULLSEYE, and then move again(choose another random number from 0 to 1000). Count the number of times they hit the ball, and the number of times the ball hits the target. Thanks




//option #2 Driving Range.
void drivingRange(char &type, double &force)
{

double elevationAngleE,horizontalDistance,initialVelocityV;
char another;
int target,random;

cout<<"Welcome to Jay's Driving Range."<<endl<<endl;

do{
cout<<"What type of club would you like to use";
cout<<"(3)-iron, (5)-iron, (7)-iron, or (9)-iron?"<<endl;
cin>>type;

cout<<"What is the % of force of the swing (0 to 100%)";
cout<<" example: 50% will be type in as 0.5"<<endl;
cin>>force;
while(force<0||force>1)
{
cout<<endl<<"Please re-enter Force";
cout<<" needs to be greater than 0 and less than 1.";
cout<<"(example: 50% will be type in as 0.5)"<<endl;
cin>>force;
}

if(type=='3')
elevationAngleE=20;
else if(type=='5')
elevationAngleE=40;
else if(type=='7')
elevationAngleE=60;
else
elevationAngleE=80;

initialVelocityV=force*150;


cout<<"To make it a more interesting, we added a moving target";
cout<<" please pick a random number from 0 to 1000 feet."<<endl<<endl;
cin>>random;
srand(time(NULL));

horizontalDistance=elevationTotal(elevationAngleE,initialVelocityV);
displayElevation(horizontalDistance);

target=rand() % 1000 + 1;
cout<<target<<endl;


cout<<"Do you want to try a different club?";
cin>>another;
while(another !='y'&& another!='n')
{cout<<endl<<"Please enter 'y' or 'n'"<<endl<<endl;
cin>>another;}
}
while (another=='y');
}
Your srand is seeding rand() again and again. I advise you to put that line outside of the do/while block.
Topic archived. No new replies allowed.