English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

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.

2006-11-25 13:35:00 · 1 answers · asked by Christina 2 in Computers & Internet Programming & Design

1 answers

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);
}

2006-11-25 13:59:49 · answer #1 · answered by Anonymous · 0 0

fedest.com, questions and answers