Hello,

I am trying to explain this step by step:

1st funcn: takes 3 values from the user & calculates the total.
2nd & 3rd funcn:irrelevant to my doubt.so,just skipping it.

Now this above funcns r repeated till user types
"END".(in the main )

4th funcn :if any of the 3 values from the 1st funcn are not zero
then displays the total no. of persons.

So my doubt is how to calculate total no. of people in the 4th funcn.

I have tried using counter in the 4th funcn by declaring a vaid condition ,but unsuccessful.
like :
Code:
``` if (t1!=0&&t2!=0&&t3!=0)
{
counter++;
}
cout<<"no.of persons"<<counter<<endl;```
please tell me what I am suppose to do?????

2. If the three values the user enters represent people, then
Code:
```if (t1!=0||t2!=0||t3!=0)
{
counter = t1+t2+t3;
cout<<"no.of persons"<<counter<<endl;
}```

3. ## Thank,but...

Hi swoopy
but unfortunately thats not the case:

user enters 3 values for time say 18secs,15secs etc.
here condn is if t1||t2||t3==0 totaltime is not calculated. or else its not then total time is calculated.
Now this procedure of entering values and calculatin time goes on till user presses END

I have to declare another funcn ,where if all the values entered by user are not zero,I have to calculate the total no. of persons who have nonzero values.

thanks,please let me know,how should i proceed??

4. ## my code

Code:
```
int calctottime(int time,int time1 ,int time2)
{
cout & cin statements for entering and reading the values
if(time!=0||time1!=0||time2!=0)
{
totalTime=time+time1+time2;

}
else
{
cout<<"total time:not completed"<<endl;
}

void totalcompet()
{
int ti=0;
int ti1=0;
int ti2=0;
if(ti!=0&&ti1!=0&&ti2!=0)//these values r                           actully the above                           funcn's times//
{
counter++;//to count the no. of persons
}
cout<<"total no. of people"<<counter<<endl;

}```

Code:
```int calctottime(int &time,int &time1 ,int &time2);
int totalcompet(int ti, int ti1, int ti2);

int main(void)
{
int time, time1, time2;
int total_time, total_competitors;

total_time = calctottime(time,time1,time2);
total_competitors = totalcompet(time,time1,time2);
return 0;
}

int calctottime(int &time,int &time1 ,int &time2)
{
cout & cin statements for entering and reading the values
if(time!=0||time1!=0||time2!=0)
{
totalTime=time+time1+time2;

}
else
{
cout<<"total time:not completed"<<endl;
}

int totalcompet(int ti, int ti1, int ti2)
{
int counter = 0;
if(ti!=0)
counter++;//to count the no. of persons
if(ti2!=0)
counter++;
if(ti3!=0)
counter++;
cout<<"total no. of people"<<counter<<endl;
return counter;
}```

6. ## not expected result

Hi swoopy,

ur suggested code ,when implemented in my prog,is displaying the same number of total people as well as people who completed all stages;

that means:

ouput is something like this:
total no. of people: 3 //(which i calculated by introducing other funcn,which works properly)//
total no. of people with all stages complete:3
//(even though we have given condns of t1!=0 ,t2!=0 ,t3!=0,then only it should calculate total people,or else it should skip the person who have any 0 time.

now, what u want me to do???????????
HEEEEELp ,i am going insane
thanks

7. ## can no one help me???

thanksssssss.......

8. ## Where r codegurus???

No one on this board is so considerate????????
I not asking to write a code for me,
but please just give me a hint......

9. I think we need a description of the original programming problem.

We have three times. Now if each time is the time for one competitor, then how can we know whether they completed all stages, all we have is one time? How many stages are there, and don't we need to know what their time is for each stage, not just one time?

Now if the three times are times for one competitor, then you need a loop. For each competitor add up the three times. Check to see if all times are >0, else not all stages were completed. So your count for total competitors is incremented each time thru the loop. Your count for all stages complete is only incremented if all times > 0.

10. ## thanks for ur reply..

Hi,
ur reply have given me some hope,that still there r people who come in need........
anyway,
the Q is input name, swimtime, runtime,cycle time from the user
and calculate the total time,but condn is if any of the entered times is 0 ,u should not calcuate total time ,instead output "total time not completed".
this stuff goes on till user enters "end" in the name.
once end is entered:
now the second phase of the Q:
calculate total no. of all competitors (which i did,by placing a counter )
and calculate total no. of competitors who completed all the stages ie(time1& time2& time3!=0)
now as i have been told to insert this stuff in different functions:

so i have worked on this funcns:
1)getname --to get the name from the user
2)calctotaltime--to calculate total time
3)totalcompetitors---total no.of all compet.
4)total no. of competitors who actually completed all stages--//I am stucked)

thanks.........

11. Ok, makes sense now. You don't really need a function for # 3, as this is just a counter. For #4, I made a function called all_stages_completed(). Here's an example. Take what you have and add the function all_stages_completed() to your code. If you can think of a better name for it, use that. I didn't make a getname() function, but one could easily be added.
Code:
```#include <iostream>

using namespace std;
bool all_stages_completed(int t1, int t2, int t3);
void calctotaltime(char name[], int t1, int t2, int t3);

int main(void)
{
char name[80];
int swim_time, run_time, cycle_time;
int total_competitors = 0;
int total_finishers = 0;
do {
cout << "Enter name:";
cin >> name;
if (strcmp(name,"end") == 0)
break;
total_competitors++;
cout << "Enter swim time:";
cin >> swim_time;
cout << "Enter run time:";
cin >> run_time;
cout << "Enter swim time:";
cin >> cycle_time;
if (all_stages_completed(swim_time,run_time,cycle_time))
{
calctotaltime(name,swim_time,run_time,cycle_time);
total_finishers++;
}
} while (true);
cout << "Total competitors:" << total_competitors << endl;
cout << "Total finishers:" << total_finishers << endl;
return 0;
}

void calctotaltime(char name[], int t1, int t2, int t3)
{
cout << "Total time for" << name << ":" << t1+t2+t3 << endl;
}

bool all_stages_completed(int t1, int t2, int t3)
{
if (t1 > 0 && t2 > 0 && t3 > 0)
return true;
else
{
cout << "Total time not completed." << endl;
return false;
}
}```

12. ## U r a genius

Thanks swoopy,
u r just adorable!!!!!!!!thanks for everything........
Still there r 2-3 more points to be added ,like best competitor overall,best competitor in swim,run etc,but I will do it myself ....
if I require a hint I will approach again..........
May God bless U