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

Design 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.

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.

Add a statement to the Main ( ) method so that after it calls the methods to convert seconds to minutes and seconds, it passes the same value to the new method to convert it to hours, minutes and seconds

2007-02-04 05:23:05 · 1 answers · asked by CR 2 in Computers & Internet Programming & Design

I have this so far but I get errors.
class Program
{
static void Main(string[] args)
{

int timeMinutes;
int timeHours;

main()
{
int seconds = 66;
int minutes = seconds / 60;
timeHours(seconds);
}


printMinutes(int time)
{
int min = x % 60;
int sec = x - (min *60);
}

printHours (int x)
{
int hrs = x % 3600;
int sec = x - (hrs *3600) ;
int min = sec % 60;
sec -= (60*min);
}


}
}

2007-02-04 05:23:51 · update #1

1 answers

I'll help you out with the printHours, and you'll be able to figure out the rest.

The % will give you the remainder.

We'll start with a simple example and work our way up.

Say you have 3600 seconds, how many hours is that? It's 1. What's the remainder? It's 0.

So:
int hrs = x/3600;


Ok, How about if we add a minute to that, 3660 seconds.

int hrs = x/3600;

There's a minute left over.

int min = (x-3600*hrs )/60
If you want to use % you would do this instead:
int min= (x%3600)/60


We could come up with another example which included seconds and would have similar logic. Jumping to the code:

int sec = x-3600*hrs - 60*min
or
int sec = x%60
(the remainder after you calculate the total number of minutes)

2007-02-04 05:42:13 · answer #1 · answered by Vegan 7 · 0 0

fedest.com, questions and answers