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-03 14:06:08 · 4 answers · asked by CR 2 in Computers & Internet Programming & Design

Here is what I have so far: What ex
namespace ConsoleApplication1
{
class Program
{
public static void Main()
{
int seconds = 66;
int minutes = seconds / 60;

int seconds = seconds - minutes*60;
Console.WriteLine(seconds,minutes);
}

printHours(int time)
{
Console.WriteLine();
}

2007-02-03 14:06:24 · update #1

It's not homework, its an exercise we have to do for our own benefit and to help study for a midterm. :-)

2007-02-03 15:21:29 · update #2

C# stands for C sharp

2007-02-03 15:27:52 · update #3

4 answers

Shouldn't your methods be external of main?
I would think (if this is a typical exercise) you need to be passing a parameter to methods. The method does its thing (ie. display value) with affecting the original value back in main.

void timeInMinutes (int);
void timeinHours (int);

main{
int seconds = 66;
timeInMinutes(seconds);
timeInHours(seconds);
}


void timeInMinutes (int t) {
int min = t % 60;
int sec = t - (min *60);
}

void timeinHours (int t) {
int hrs = t % 3600;
int sec = t - (hrs *3600) ;
int min = sec % 60;
sec -= (60*min);
}

2007-02-03 14:28:58 · answer #1 · answered by Alan 6 · 0 0

///assuming given is your input
///seconds and mins should hold the output values for method 1
///seconds mins2 and hrs should hold method 2's
///first req.
int seconds = given % 60;
int mins = given / 60;

///second req.
int hrs = given / 3600;
int mins2 = (given - 3600 * hrs - seconds) / 60;

///I hope you can fill up the rest in c#

2007-02-03 22:40:44 · answer #2 · answered by ans_bros 1 · 0 0

Is this a homework?

/------copied from your code---/
int seconds = 66;
int minutes = seconds / 60;

int seconds = seconds - minutes*60; <-- this line here will be an error you do not need to redeclare the variable "seconds". Remove "int" to fix.
Console.WriteLine(seconds,minu...

/-----------------/

int hours = minutes / 60;
minutes = minutes - hours * 60;

Console.Writeline(seconds, minutes, hours)
------------------------------------------------------------------

Is this ok?

2007-02-03 22:28:38 · answer #3 · answered by Allen.Silkenhut 2 · 0 0

looks good to me... what does C# mean?

2007-02-03 22:11:09 · answer #4 · answered by Anonymous · 0 2

fedest.com, questions and answers