Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

An ironman race consists of a 2.4 mile swim, a 112 mile bike ride, and a 26.2 mi

ID: 3907479 • Letter: A

Question

An ironman race consists of a 2.4 mile swim, a 112 mile bike ride, and a 26.2 mile run. Have the user enter a name and the times for the three events for four participants. Time will be entered in hours, minutes, and seconds. Decide who is the winner in each event and for the overall race. Also calculate the speed of each participant in miles per hour in each event. The output should be (name) Swim: Finished in (hours):(minutes):(seconds) going (speed) mph Cycling: Finished in (hours):(minutes):(seconds) going (speed) mph Run: Finished in (hours):(minutes):(seconds) going (speed) mph Overall: Finished in (hours):(minutes):(seconds) going (speed) mph. Winners: Swim: (name) Cycling: (name) Run: (name) Overall: (name) Sample times: Luke 00:51:17 04:22:25 02:57:20 Sam 00:54:13 04:22:33 02:58:35 Julie 00:51:13 04:34:21 02:52:37 Chris 00:51:02 04:34:39 02:53:18

Explanation / Answer

//Code in C language

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
//cycling is taken as Riding here
int min(int a,int b, int c, int d)
{
   int m1=(a<b)?((a<c)?a:c):((b<c)?b:c);
   if(d<m1)
       return d;
   else
       return m1;
}
int main()
{
   int sw_h1,sw_h2,sw_h3,sw_h4,sw_m1,sw_m2,sw_m3,sw_m4,sw_s1,sw_s2,sw_s3,sw_s4;//for swimming hh:mm:ss
   int rd_h1,rd_h2,rd_h3,rd_h4,rd_m1,rd_m2,rd_m3,rd_m4,rd_s1,rd_s2,rd_s3,rd_s4;//for riding hh:mm:ss
   int rn_h1,rn_h2,rn_h3,rn_h4,rn_m1,rn_m2,rn_m3,rn_m4,rn_s1,rn_s2,rn_s3,rn_s4;//for running hh:mm:ss
   char p1[20],p2[20],p3[20],p4[20]; // Participants names
   char sw_winner[20]=" ",rd_winner[20]=" ",rn_winner[20]=" "; // for storing final winners in each sport
   int p1_sw,p2_sw,p3_sw,p4_sw,p1_rd,p2_rd,p3_rd,p4_rd,p1_rn,p2_rn,p3_rn,p4_rn;    // for converting time into seconds to find minimum time
  
   float p1_spd_sw,p2_spd_sw,p3_spd_sw,p4_spd_sw;    // for calculating speed in mph in swimming
   float p1_spd_rd,p2_spd_rd,p3_spd_rd,p4_spd_rd;   // for calculating speed in mph in riding
   float p1_spd_rn,p2_spd_rn,p3_spd_rn,p4_spd_rn;   // for calculating speed in mph in running
  
   int sw_result,rd_result,rn_result;           // for storing the result of participants using minimum timings
  
   printf("********ENTER DETAILS ********* ");
   printf("Enter Time in hh:mm:ss format");
   printf(" NAME SWIM RIDING RUNNING ");
   scanf("%s",p1);
   scanf("%d:%d:%d",&sw_h1,&sw_m1,&sw_s1);
   scanf("%d:%d:%d",&rd_h1,&rd_m1,&rn_s1);
   scanf("%d:%d:%d",&rn_h1,&rn_m1,&rn_s1);
  
  
   scanf("%s",p2);
   scanf("%d:%d:%d",&sw_h2,&sw_m2,&sw_s2);
   scanf("%d:%d:%d",&rd_h2,&rd_m2,&rn_s2);
   scanf("%d:%d:%d",&rn_h2,&rn_m2,&rn_s2);
  
   scanf("%s",p3);
   scanf("%d:%d:%d",&sw_h3,&sw_m3,&sw_s3);
   scanf("%d:%d:%d",&rd_h3,&rd_m3,&rn_s3);
   scanf("%d:%d:%d",&rn_h3,&rn_m3,&rn_s3);
  
   scanf("%s",p4);
   scanf("%d:%d:%d",&sw_h4,&sw_m4,&sw_s4);
   scanf("%d:%d:%d",&rd_h4,&rd_m4,&rn_s4);
   scanf("%d:%d:%d",&rn_h4,&rn_m4,&rn_s4);
  
  
   //Convert into seconds  
   p1_sw= sw_h1*3600 + sw_m1*60+ sw_s1;
   p2_sw= sw_h2*3600 + sw_m2*60+ sw_s2;
   p3_sw= sw_h3*3600 + sw_m3*60+ sw_s3;
   p4_sw= sw_h4*3600 + sw_m4*60+ sw_s4;
  
   p1_rd= rd_h1*3600 + rd_m1*60+ rd_s1;
   p2_rd= rd_h2*3600 + rd_m2*60+ rd_s2;
   p3_rd= rd_h3*3600 + rd_m3*60+ rd_s3;
   p4_rd= rd_h4*3600 + rd_m4*60+ rd_s4;
  
   p1_rn= rn_h1*3600 + rn_m1*60+ rn_s1;
   p2_rn= rn_h2*3600 + rn_m2*60+ rn_s2;
   p3_rn= rn_h3*3600 + rn_m3*60+ rn_s3;
   p4_rn= rn_h4*3600 + rn_m4*60+ rn_s4;
  
   //finding minimum time in each sport
   sw_result=min(p1_sw,p2_sw,p3_sw,p4_sw);
   rd_result=min(p1_rd,p2_rd,p3_rd,p4_rd);
   rn_result=min(p1_rn,p2_rn,p3_rn,p4_rn);
  
   if(sw_result==p1_sw)
       strcpy(sw_winner,p1);
   else if(sw_result==p2_sw)
       strcpy(sw_winner,p2);
   else if(sw_result==p3_sw)
       strcpy(sw_winner,p3);
   else
       strcpy(sw_winner,p4);
      
      
   if(rd_result==p1_rd)
       strcpy(rd_winner,p1);
   else if(rd_result==p2_rd)
       strcpy(rd_winner,p2);
   else if(rd_result==p3_rd)
       strcpy(rd_winner,p3);
   else
       strcpy(rd_winner,p4);
      
   if(rn_result==p1_rn)
       strcpy(rn_winner,p1);
   else if(rn_result==p2_rn)
       strcpy(rn_winner,p2);
   else if(rn_result==p3_rn)
       strcpy(rn_winner,p3);
   else
       strcpy(rn_winner,p4);      
  
   // for calculating speed in miles per hour
   p1_spd_sw=2.4/p1_sw * 3600;
   p2_spd_sw=2.4/p2_sw * 3600;
   p3_spd_sw=2.4/p3_sw * 3600;
   p4_spd_sw=2.4/p4_sw * 3600;
  
   p1_spd_rd=2.4/p1_rd * 3600;
   p2_spd_rd=2.4/p2_rd * 3600;
   p3_spd_rd=2.4/p3_rd * 3600;
   p4_spd_rd=2.4/p4_rd * 3600;
  
   p1_spd_rn=2.4/p1_rn * 3600;
   p2_spd_rn=2.4/p2_rn * 3600;
   p3_spd_rn=2.4/p3_rn * 3600;
   p4_spd_rn=2.4/p4_rn * 3600;
  
   // For displaying the output
   printf(" %s ",p1);
   printf("Swim: Finished in %d:%d:%d going speed %f mph ",sw_h1,sw_m1,sw_s1,p1_spd_sw);
   printf("Riding: Finished in %d:%d:%d going speed %f mph ",rd_h1,rd_m1,rd_s1,p1_spd_rd);
   printf("Running: Finished in %d:%d:%d going speed %f mph ",rn_h1,rn_m1,rn_s1,p1_spd_rn);
  
  
   printf(" %s ",p2);
   printf("Swim: Finished in %d:%d:%d going speed %f mph ",sw_h2,sw_m2,sw_s2,p2_spd_sw);
   printf("Riding: Finished in %d:%d:%d going speed %f mph ",rd_h2,rd_m2,rd_s2,p2_spd_rd);
   printf("Running: Finished in %d:%d:%d going speed %f mph ",rn_h2,rn_m2,rn_s2,p2_spd_rn);
  
  
   printf(" %s ",p3);
   printf("Swim: Finished in %d:%d:%d going speed %f mph ",sw_h3,sw_m3,sw_s3,p3_spd_sw);
   printf("Riding: Finished in %d:%d:%d going speed %f mph ",rd_h3,rd_m3,rd_s3,p3_spd_rd);
   printf("Running: Finished in %d:%d:%d going speed %f mph ",rn_h3,rn_m3,rn_s3,p3_spd_rn);
  
  
   printf(" %s ",p4);
   printf("Swim: Finished in %d:%d:%d going speed %f mph ",sw_h4,sw_m4,sw_s4,p4_spd_sw);
   printf("Riding: Finished in %d:%d:%d going speed %f mph ",rd_h4,rd_m4,rd_s4,p4_spd_rd);
   printf("Running: Finished in %d:%d:%d going speed %f mph ",rn_h4,rn_m4,rn_s4,p4_spd_rn);
  
   printf(" *************WINNERS************** ");
   printf("Swimming : %s ",sw_winner);
   printf("Riding: %s ",rd_winner);
   printf("Running : %s ",rn_winner);
  
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote