Call function

I am working on a program right now to determine whether a not a person participating in a race qualifies for the next round based on their age and the time it took them to complete the first race. I am not sure if I am correctly coding the function to do just that so any input on what I can do what be greatly appreciated. Also I need to keep count of the people that do qualify, the numbers are coming from a data file that I am reading in.

//Qualify function recieves age and time and determines if they qualify
int Qualify(int age, int time)
{
//Variables
i=0;
string qualifies;
string not;
do
while (i != -1)
{
if (age < 30 && time <=300) // Checks age and time
{
cin >> qualifies;

else if (age <30 && time >300)
cin >> not;
}

if (age >= 30 && age <= 50 && time <= 360)
{
cin >> qualifies;
else if (age >=30 && age <= 50 && time >360)
cin >> not;
}

if (age > 50 && time <= 420)
{
cin >> qualifies;
else
cin >> not;
}
}




(this is just the function, the infile call is in the main function)

Thanks again
I wasn't quite sure what you asked. But i 100% think it is this...
And i saw your function beginning with big letter... Remember C++ is case-sensitive...What is "do" doing here?


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
int qualify(int age, int time)
{
//Variables
i=0;
string qualifies;
string not;
int participants = 0;

while (i != -1){
cout << "There are currently " << participants << " ready now. " << endl;
{
if (age < 30 && time <= 300) // Checks age and time 
{
cin >> qualifies;
participants++;

}

if (age < 30 && time > 300){
cin >> not;
}

if (age >= 30 && age <= 50 && time <= 360)
{ 
cin >> qualifies;

participants++;
}
 if (age >=30 && age <= 50 && time >360){
cin >> not;
}

if (age > 50 && time <= 420){
        

cin >> qualifies;
participants++;
}
else{ 
cin >> not;
}
}
}


Last edited on
Yeah sorry I tried to be as clear as possible, but this really did help alot, I realize I needed a participants variable and how to keep count of them most importantly.


So here is my next problem, I am reading in data from a file and it is age, and race time. throughout the data they switch which side the race time and age is on, (like this)

Age RT

12 240
23 300
55 229
40 270
320 22
400 50
___________

I need a function that understands that the bigger number is the race time, this is what I have.


void CheckAgeTime(int &age, int &time)
{
while (i != -1)
{
i=0;
if (age > time)
{
swap(age,time);
else

}

}
}


Pretty sure this is not right, but its really all I have come up with.
this is the last part of my program that needs fixed, so any pointers on how to set up this function would be great, Thanks again.


Set the "i" variable above the "while(i != -1)" ...



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
void CheckAgeTime(int &age, int &time)
{
     i = 0;
while (i != -1)
{

if (age > time)
{
swap(age,time);
}
else 
{
 cout << " " << endl;
}


}
Last edited on
Topic archived. No new replies allowed.