C# – Object Oriented Programming – Lab 3

Write a program that reads a value representing a number of seconds and returns the equivalent amount of time in days, hours, minutes, and seconds.

Here’s my solution for it:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            int totalSeconds = 111143;
            Console.WriteLine(totalSeconds + " seconds");

            int min = 0;
            int hour = 0;
            int day = 0;

            while (totalSeconds >= 60)
            {
                totalSeconds = totalSeconds - 60;
                min++;
            }

            while (min >= 60)
            {
                min = min - 60;
                hour++;
            }

            while (hour >= 24)
            {
                hour = hour - 24;
                day++;
            }

            Console.Write(day + " Days " + hour + " Hours " + min + " Min " + totalSeconds + " Seconds");
            Console.ReadKey();
        }
    }
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s