I have a program that lets me enter participants in a race, their startingnumber, their start time and end time. The program then tell me who won the race and the winning time.
This is my program:
#include <iostream>
using namespace std;
int main ()
{
int start_Nr, start_Hour, start_Min, start_Sec, end_Hour, end_Min, end_Sec;
int end_Time, shortest_Time, fastest_Runner;
bool firstPerson = true;
cout << "Enter start Number: ";
cin >> start_Nr;
while (start_Nr >0)
{
cout << "Enter start time: ";
cin >> start_Hour >> start_Min >> start_Sec;
cout << "Enter end time: ";
cin >> end_Hour >> end_Min >> end_Sec;
end_Time = (((end_Hour * 3600) + (end_Min * 60) + end_Sec) - ((start_Hour * 3600) + (start_Min * 60) + start_Sec));
if (end_Time < shortest_Time || firstPerson == true)
{
shortest_Time = end_Time;
fastestRunner = start_Nr;
}
cout << "Enter start Number: ";
cin >> start_Nr;
firstPerson = false;
}
cout << "The fastest time was: " << shortest_Time << endl;
cout << "The fastest runner was: " << fastest_Runner << endl;
}
My only problem is that what if someone starts five minutes to midnight and end ten minutes AFTER midnight. How do I handle the time then? It's bound to be negative if I dont come up with something smart. I want it to be as simple as possible (I'm very new to this) so no arrays or such... Thanks