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!

1) Yes. The method GetNumberOfSeconds returns an integer which is being assigned to totalSeconds.

2) totalSeconds is being used as a parameter (a value sent to a method). And yes, leftOverSeconds is the amount of seconds that aren't a full hour.

3) Techinically it's dividing it by NUMBER_OF_SECONDS_IN_AN_HOUR which you have set to 3600. You could set it to 5 if you wanted, but you'd get the wrong answer :)

4) NUMBER is the second parameter of the method. When you call this method, you need to pass it two values which will become (in the method) sec and NUMBER. If you look at line 25 where you call this method, you'll see that there are two variables inside the (): totalSeconds and NUMBER_OF_SECONDS_IN_AN_HOUR. These values are used as the values of sec and NUMBER. We won't get into pass-by-value and pass-by-reference right now :)

5) leftOver is the name that this method will used to refer to the first parameter when the method is called.

6) It's returning the value from the mathmatical operation on line 76: leftOver modulus NUMBER_OF_SECONDS_IN_A_MINUTE. Don't confuse the parameter NUMBER_OF_SECONDS_IN_A_MINUTE with the static value in line 13. While they have the same name, they are not the same variables. This has to do with something called scope, which you'll need to understand as a programmer.

wow your awesome Momerath, Im gaining so fast everyday with your help. Thank you so much again!

For you answer in #6 how do you know its "NUMBER_OF_SECONDS_IN_A_MINUTE" instead of hour (i may be missing something..)

Because it literally says "NUMBER_OF_SECONDS_IN_A_MINUTE" on line 76.

ohhh my bad , I didnt see the variable declared with the int data type thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.