This is in C#. Please use comment blocks. I am trying to learn. Thanks a bunch!
Your instructor enjoys running races of different distances. Write a program to allow him to calculate his pace for a race. Your program should ask for following:
Paces should be displayed to the nearest seconds. Distances should be displayed to precisely 1 decimal place. Your calculations should be done at full precision. E.g:
1:53:30 (1 hour, 53 minutes, 30 seconds) for 13.1 miles (a half marathon) is 8:40 per mile (8 minute and 40 seconds)
Your output should look like this
Time: 1:53:30
Distance in miles: 13.1 Distance in km: 21.1
Pace in minutes per mile: 8:40 Pace in minutes per km: 5:23
using System;
public class PaceCalculation
{
public static void Main()
{
float dist , hrs, min, sec, tsec, mph, mps, kph, distmiles;
Console.Write(" Enter time - Hour: ");
hrs = Convert.ToSingle(Console.ReadLine());
Console.Write(" Enter time - Min: ");
min = Convert.ToSingle(Console.ReadLine());
Console.Write(" Enter time - Sec: ");
sec = Convert.ToSingle(Console.ReadLine());
Console.Write(" Enter the distance of race (Km) : ");
dist =Convert.ToSingle(Console.ReadLine());
tsec = (hrs*3600) + (min*60) + sec;
mps = dist/tsec;
kph =( dist/tsec)*(5/18);
mph = kph / 1.609f;
distmiles= dist/1.609f;
Console.Writeline("The time output : " hrs , ":", min , ":",sec);
Console.Writeline("Distance is miles: " , distmiles);
Console.Writeline("Distance is km ", dist);
Console.Writeline("Pace in minutes per mile: ", mps);
Console.Writeline("Pace in minutes per km: ", mph);
Console.Writeline("Pace in hours per km: ", kph);
}
}
EXPLANATION:
you simplyhave to use the formula speed=distance/time.
Get Answers For Free
Most questions answered within 1 hours.