Ok so while working on this I want to figure out at about line 23 for "hours" I understand the argument "NUMBER_OF_SECONDS_IN_AN_HOUR" but not "totalSeconds" is totalseconds the value coming from : "totalSeconds= GetNumberOfSeconds();" ? Which is the input received by the user?
For lines 25-29
, how does totalSeconds play into each method , and is leftOverSeconds basically after the calculations from the previous method the left over value's ?
Lines 55-59, the division operation thats happening is returning the data (which are in seconds) and then dividing by 60 as I have commented correct?
Lines 61-64 , it is returning "seconds" value and doing a modulus operation on what "NUMBER" ? I dont understand what "NUMBER" is representing here....
Lines 67-69 , what value does "leftOver" represent is it the resulting value from the method before it ?
Lines 72-76 , Lastly I don't know what the compiler is exactly "returning" it says leftOver but Im confused if its again values resulting from computation from each previous method ..
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SecondsToHours
{
class SecondsToHours
{
static void Main(string[] args)
{
const int NUMBER_OF_SECONDS_IN_AN_HOUR = 3600;
const int NUMBER_OF_SECONDS_IN_A_MINUTE = 60;
int totalSeconds,
hours,
minutes,
leftOverSeconds;
DisplayInstructions();
totalSeconds = GetNumberOfSeconds();
//calculates and writes the number of hours
hours = CalculateHours(totalSeconds, NUMBER_OF_SECONDS_IN_AN_HOUR);
//after hours are calculated the values remaining pushed into "leftOverSeconds"
leftOverSeconds = CalculateWhatsLeft(totalSeconds, NUMBER_OF_SECONDS_IN_AN_HOUR);
//minutes are calculated here using values from "leftOverSeconds"
minutes = CalculateMinutes(leftOverSeconds, NUMBER_OF_SECONDS_IN_A_MINUTE);
//leftOverSeconds calculated using value remaining from "leftOverSeconds"
leftOverSeconds = CalculateSeconds(leftOverSeconds, NUMBER_OF_SECONDS_IN_A_MINUTE);
DisplayResults(leftOverSeconds, totalSeconds, hours, minutes);
}
public static void DisplayInstructions()
{
Console.WriteLine(".....Instructions about the program.");
}
public static int GetNumberOfSeconds()
{
// inValue a "identifier" to recieve input from the user
string inValue;
int seconds;
Console.Write("\n\nPlease enter the number of seconds: ");
//this recieives input(from keyboard) from the user
inValue = Console.ReadLine();
//Forced conversion of input from user to "seconds"
seconds = int.Parse(inValue);
//returns data as "Seconds" .
return seconds;
}
public static int CalculateHours(int seconds, int NUMBER_OF_SECONDS_IN_AN_HOUR)
{
//this will return the value recieved for "seconds" and then divide by "60"
return seconds / NUMBER_OF_SECONDS_IN_AN_HOUR;
}
public static int CalculateWhatsLeft(int sec, int NUMBER)
{
//modulus operation ,divides seconds by the "numbers"(value) left over from calculating hours
return sec % NUMBER;
}
public static int CalculateMinutes(int leftOver, int NUMBER_OF_SECONDS_IN_A_MINUTE)
{
return leftOver / NUMBER_OF_SECONDS_IN_A_MINUTE;
}
public static int CalculateSeconds(int leftOver, int NUMBER_OF_SECONDS_IN_A_MINUTE)
{
//this will calculate the number of seconds by doing a modulus operation with the leftOver values from minutes , to convert
//to seconds
return leftOver % NUMBER_OF_SECONDS_IN_A_MINUTE;
}
//this will Display the values calculated for leftOverSeconds,totalSeconds, hours, and minutes
public static void DisplayResults(int leftOverSeconds, int totalSeconds,
int hours, int minutes)
{
Console.Clear();
Console.WriteLine("Total Seconds: {0:N0}\n\n", totalSeconds);
Console.WriteLine("Hours\tMinutes\tSeconds");
Console.WriteLine("-----\t-------\t-------");
Console.WriteLine(hours + "\t" + minutes + "\t" + leftOverSeconds);
Console.Read();
}
}
}
Thank you again as always!