Hi I have my code but can't figure out the last part of this.
Here is my code:
using System;
public class CalculateTime
{
// Main method entry point
public static void Main()
{
//initialize variabls
int seconds = 0;
//input number of seconds
string inputSeconds;
Console.Write("Input the number of seconds: ");
inputSeconds = Console.ReadLine();
seconds = Convert.ToInt32(inputSeconds);
//call CalcMin method
CalcMin(seconds);
}
//CalcMin method
public static void CalcMin(int x)
{
int totalMinutes = 0, totalSeconds = 0;
totalMinutes = x / 60;
totalSeconds = x % 60;
//output number of minutes and seconds
Console.WriteLine("{0} minute(s), {1} second(s)", totalMinutes, totalSeconds);
}
}
the last part should be as follows:
Add a second method to the solution. This method displays a passed argument as hours, minutes and seconds. For example 3666 seconds is 1 hour, 1 minute and 6 seconds.
Help with C# end of program?
I guess I am going to do your homework for you after all.
public static void CalcHrs(int x) {
int totalMinutes = 0, int totalSeconds = 0, int totalHours = 0;
totalSeconds = x;
totalMinutes = x / 60;
totalHours = totalMinutes / 60;
totalSeconds = totalSeconds - (totalMinutes * 60);
totalMinutes = totalMinutes - (totalHours * 60);
Console.WriteLine("{0} hour(s), {1} minute(s), {2} second(s)", totalHours, totalMinutes, totalSeconds);
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment