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

Time Calculator in c# Create an application that lets the user enter a number of

ID: 3890914 • Letter: T

Question

Time Calculator in c#

Create an application that lets the user enter a number of seconds and works as follows:

1. There are 60 seconds in a min. If the number of seconds entered by the user is greater than or equal to 60, the program should display the number of minutes in that manhy seconds.

2. There are 3,600 seconds in an hour. If the number of seconds entered by the user is greater than or equal to 3,600, the program should display the number of hours in that many seconds.

3. There are 86,400 seconds in a day. If the number of seconds entered by the user is greater than or equal to 86,400, the program should display the number of days in that many seconds.

Explanation / Answer

using System.IO;
using System;

class Program
{
static void Main()
{
int intTemp = Convert.ToInt32(Console.ReadLine());
var timeSpan = TimeSpan.FromSeconds(intTemp);
var dy = TimeSpan.FromSeconds(86400);
var hr = TimeSpan.FromSeconds(3600);
var sec = TimeSpan.FromSeconds(60);
if (timeSpan > dy)
{
int dd = timeSpan.Days;
Console.WriteLine("Days:{0}", dd);
}
else if (timeSpan > hr)
{
int hh = timeSpan.Hours;
Console.WriteLine("Hours:{0}", hh);
}
else if (timeSpan > sec)
{
int mm = timeSpan.Minutes;
Console.WriteLine("Minutes:{0}", mm);
}
  
}
}

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