473,509 Members | 10,100 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Double method problem

1 New Member
Hello, this is my 1st time posting here. I'm enrolled in a CIS course through devry. This is my assignment:

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


I'm getting an error in the Sub method stating that an identifier is expected. This is what i've coded so far:
Expand|Select|Wrap|Line Numbers
  1. using System;
  2. public class convertingSeconds
  3. {
  4.     public static void Main()
  5.     {
  6.         string secondsString;
  7.         int minutes, seconds, hours;
  8.         Console.Write("Please enter the ammount of seconds you would like calculated");
  9.         secondsString = Console.ReadLine();
  10.         seconds = Convert.ToInt32(secondsString);
  11.         hours = Seconds / 3600;
  12.         minutes = Seconds / 60;
  13.         minutes = minutes % hours;
  14.         using (TimeSpan = t)
  15.         seconds = t.seconds;
  16.         minutes = t.minutes;
  17.         hours = t.hours;
  18.         secondsString = t.secondsString;
  19.         Sub(t);
  20.     }
  21.     public static void Sub(t)
  22.     {
  23.         Console.WriteLine("{0} seconds is,{1} minutes, {2} seconds", t.secondsString, t.minutes, t.seconds);
  24.         Console.ReadLine();
  25.         Console.WriteLine("{0} seconds is {1} hours, {2} minutes, {3} seconds", t.secondsString, t.hours, t.minutes, t.seconds);
  26.         Console.ReadLine();
  27.     }
  28.  
Any input would be greatly appreciated! Thanks!!

-Andy
Aug 4 '07 #1
1 1168
bradirby
2 New Member
You need to put an identifier type in the Sub definition. The compiler doesn't konw what type of variable t is. Try this:

public static void Sub( TimeSpan t)

A couple more hints:

C# is case sensitive - make sure variables are cased properly

The variable you're assigning to goes on the left. The statement
seconds = t.seconds;
will copy the value out of t.seconds and put it into the variable seconds, which appears to be the opposite of what you want.

A Using statement creates a variable then throws it away automatically when that variable goes out of scope. Since you have no { and } around the lines after the Using statement, that means it has a scope of 1 line (the one immediately following). Put { and } around everything that needs to use the t variable.

good luck
Aug 4 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
6075
by: DAVID SCHULMAN | last post by:
I've been trying to perform a calculation that has been running into an underflow (insufficient precision) problem in Microsoft Excel, which calculates using at most 15 significant digits. For this...
6
7252
by: James Thurley | last post by:
According to the docs, floats are 32 bit and doubles are 64 bit. So using floats should be faster than using doubles on a 32 bit processor, and my tests confirm this. However, most of the Math...
1
3091
by: Kuba Florczyk | last post by:
Hi I've got some problem doing double buffer. Here is my problem: I've got custom control on which i paint some data (chat messages, lets call it ChatControl), this control is puted on a...
5
5639
by: Markus Kling | last post by:
"double.Parse(double.MaxValue.ToString())" yields the following Exception: Value was either too large or too small for a Double. at System.Number.ParseDouble(String value, NumberStyles options,...
0
1538
by: Xavier Osa | last post by:
Hi, I have an ASP.Net web page that you can download a file. As Fergunson's problem, it prompts twice dialog boxes only if I select Open button. If I select Save button, it prompts once. I'm...
16
5849
by: Charles Law | last post by:
I have a string similar to the following: " MyString 40 "Hello world" all " It contains white space that may be spaces or tabs, or a combination, and I want to produce an array...
7
6498
by: Rain | last post by:
Hello Gurus! I really need this one to finish a module in my thesis. PLease please help me. I need a double buffer class so i can call it and use it anytime i want, the problem is everything ive...
0
3220
by: jim4u | last post by:
I am porting a vb library to vb.net. The vb library has an external call to an unmanaged dll. Existing code: //External function declaration Private Declare Function Uncompress& Lib...
0
1723
by: jim4u | last post by:
I am porting a vb library to vb.net. The vb library has an external call to an unmanaged dll. Existing code: //External function declaration Private Declare Function Uncompress& Lib...
4
2545
by: Yoavo | last post by:
Hi, I want to convert a string to double. I use the function: "System.Convert.ToDouble". The problem is that if the string contains the character "." the program aborts. What might be the...
0
7237
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
1
7073
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7506
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5656
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5062
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4732
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1571
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
779
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
443
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.