Youre a swimmer and you want to compare all of your race tim

You\'re a swimmer, and you want to compare all of your race times to find the fastest one. Write a program that continuously takes race times as doubles from standard input, until the input is \"no more races,\" at which point it should print out the time of your fastest race.

Solution

c++ code:

#include <bits/stdc++.h>
using namespace std;
int main()
{
   double t;
   std::vector<float> myraces;
   while (true)
   {
       string s;
       cout << \"Enter race time!\ \";
       getline(cin,s);
       if(s == \"no more races\")
       {
           break;
       }
       else if(atof(s.c_str()) == 0)
       {
           cout << \"Invalid input\ \";
       }
       else
       {
               myraces.push_back(atof(s.c_str()));
       }
   }
   cout << \"fastest race you completed in \" << *min_element(myraces.begin(),myraces.end()) << \" time units\ \";
   return 0;  
}

Sample Output:

Enter race time!
2
Enter race time!
3
Enter race time!
1
Enter race time!
0.01
Enter race time!
no more races
fastest race you completed in 0.01 time units

You\'re a swimmer, and you want to compare all of your race times to find the fastest one. Write a program that continuously takes race times as doubles from st

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site