1. ## stuck on time!!!!

Hi,
Please help me out in solving this Q.I am newbie and I am not sure whether I am doing right thing??

The Q is to take swim,cycle,run times from user and display the best from each leg of competition.

I am submiiting code for calculating the best swim time:
Code:
```int main()
{
int best_swim_time=1000;
do{
if(swim_time<best_swim_time)//swim_time entered by                               user//
{

be_swim_time= swim_time;
best_swim_name= nam;
}
}while(true);```
My test data:
1st competitor:- ST:18sec,RT:3sec,CT:4sec
2nd competitor:- ST:10sec,RT:8sec.CT:13sec
results:best ST 2nd competitor (which is right)
best CT,RT again 2nd competitor(which is wrong)

1st competitor:- ST:2sec,RT:4sec,CT:9sec
2nd competitor:- ST:9sec, RT:3sec,CT :2sec
results:best RT & CT 2nd competitor(which is right)
best ST again 2nd competitor(which is wrong)

2. You need to think through your logic and then write it out in a flow chart or what ever it takes to make sense... if you can't do that then you won't be able to code it.

Here is some quick and dirty code I banged out to help you get moving. You should be able to modify it to do what you want... I hope you will not copy it verbatum... but that it up to you.

Code:
```#include <iostream>

using namespace std;

struct competitor_info {
char name[30];
int swim_time;
int run_time;
int cycle_time;
int overall_time;
};

#define MAX_COMPETITORS 3

int main()
{
competitor_info race_results[MAX_COMPETITORS];
int best_time=1000;
int competitor=0;
int winner=0;

// initialize array values;
for (int i=0; i<MAX_COMPETITORS; ++i)
{
race_results[i].name[0] = '\0';
race_results[i].swim_time = 0;
race_results[i].run_time = 0;
race_results[i].cycle_time = 0;
race_results[i].overall_time = 0;
}

do {
cout << "enter name of competitor #" << competitor+1 << ": ";
cin >> race_results[competitor].name;

cout << "enter swim time: ";
cin >> race_results[competitor].swim_time;

cout << "enter run time: ";
cin >> race_results[competitor].run_time;

cout << "enter cycle time: ";
cin >> race_results[competitor].cycle_time;

race_results[competitor].overall_time =
race_results[competitor].swim_time+
race_results[competitor].run_time+
race_results[competitor].cycle_time;

if(race_results[competitor].overall_time<best_time)
{
best_time = race_results[competitor].overall_time;
winner=competitor;
}

if (!race_results[competitor].swim_time ||
!race_results[competitor].swim_time ||
!race_results[competitor].swim_time)
{
cout << "you must compete in all events\n";
cout << "you have been disqualified\n";
}
else ++competitor;

} while (competitor < MAX_COMPETITORS);

cout << "\n\n===============================================\n";
cout << "best overall time: " << best_time << endl;
cout << "winner: " << race_results[winner].name << endl;
cout << "swim time: " << race_results[winner].swim_time << endl;
cout << "run time: " << race_results[winner].run_time << endl;
cout << "cycle time: " << race_results[winner].cycle_time << endl;

return 0;
}```