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

Can anyone help?? I am having difficulty.

A C# solution with a Main ( ) method that holds an integer variable named seconds to which you will assign a value. Create a method to which you pass this value. The method displays the seconds in minutes and seconds. As an example 66 seconds is 1 minute and 6 seconds.

2006-11-24 09:04:39 · 4 answers · asked by Christina 2 in Computers & Internet Programming & Design

4 answers

is this for homework???


class TestClass
{
static void Main(string[] args)
{
int sec;
sec = args[0];
displayTime(sec);
}
void displayTime(int sec)
{
System.Console.WriteLine( sec / 60 + " " + sec - ((sec/60) * 60));
}
}

2006-11-24 09:24:27 · answer #1 · answered by Anonymous · 1 0

Are you having trouble calculating the number of minutes/seconds given the number of seconds?

You can calculate that with this code fragment:

int seconds = 66;
int minutes = seconds / 60;
int seconds = seconds - minutes*60

minutes now holds 1 and seconds holds 6

2006-11-24 17:08:10 · answer #2 · answered by chorneck27 1 · 0 0

I'd follow SlaveMaker's suggestion for a class format (although they didn't ask you to accept command line input, they asked you to "assign a value" which may imply a mere "seconds = 100;")

You may want to use the framework's System.TimeSpan for your calculations (even if they're straightforward, it removes ambiguity and rounding errors). Basically

TimeSpan ts = new TimeSpan(0, 0, x); // where x is the number of seconds
Console.WriteLine( String.Format("{0} minute{1} and {2} second{3}", ts.Minutes, ts.Minutes == 1 ? "" : "s", ts.Seconds, ts.Seconds == 1 ? "" : "s"));

This is merely a suggestion. They may indeed want you to do the math or they may just want you to use the framework. *shrug*

2006-11-25 03:45:01 · answer #3 · answered by mrknowitall 1 · 0 0

One second...

2006-11-24 17:08:21 · answer #4 · answered by lee f 5 · 0 0

fedest.com, questions and answers