Convert Time
-
= ConvertTime(timeArray[x]); } for (int x = 0; x < timeArray.Length; x++) { Console.WriteLine(timeArray[x] + " " + decTimeArray[x]); } Console.ReadKey(); } } public static double ConvertTime(string rawTime) { int hours; int minutes; double dminutes; double decimalTime; string delimStr = ":"; char[] delimiter = delimStr.ToCharArray(); string[] split; split = rawTime.Split(delimiter); hours = Convert.ToInt32(split[0]); minutes = Convert.ToInt32(split[1]); if (minutes < 7) dminutes = 0.00; else if (minutes < 22) dminutes = 0.25; else if (minutes < 37) dminutes = 0.50; else if (minutes < 53) dminutes = 0.75; else dminutes = 1.0; return decimalTime = dminutes + hours;
-
= ConvertTime(timeArray[x]); } for (int x = 0; x < timeArray.Length; x++) { Console.WriteLine(timeArray[x] + " " + decTimeArray[x]); } Console.ReadKey(); } } public static double ConvertTime(string rawTime) { int hours; int minutes; double dminutes; double decimalTime; string delimStr = ":"; char[] delimiter = delimStr.ToCharArray(); string[] split; split = rawTime.Split(delimiter); hours = Convert.ToInt32(split[0]); minutes = Convert.ToInt32(split[1]); if (minutes < 7) dminutes = 0.00; else if (minutes < 22) dminutes = 0.25; else if (minutes < 37) dminutes = 0.50; else if (minutes < 53) dminutes = 0.75; else dminutes = 1.0; return decimalTime = dminutes + hours;
Still at it? To get a time span expressed as a floating-point number of hours but rounded to a quarter, I would try something along these lines (code not tested):
private double ToHoursButRoundedToQuarter(string s) {
TimeSpan span=TimeSpan.Parse(s);
int minutes=span.TotalMinutes+7;
int quarters=minutes/15;
return quarters*0.25;
}:)
Luc Pattyn [Forum Guidelines] [My Articles]
Avoiding unwanted divs (as in "articles needing approval") with the help of this FireFox add-in
-
= ConvertTime(timeArray[x]); } for (int x = 0; x < timeArray.Length; x++) { Console.WriteLine(timeArray[x] + " " + decTimeArray[x]); } Console.ReadKey(); } } public static double ConvertTime(string rawTime) { int hours; int minutes; double dminutes; double decimalTime; string delimStr = ":"; char[] delimiter = delimStr.ToCharArray(); string[] split; split = rawTime.Split(delimiter); hours = Convert.ToInt32(split[0]); minutes = Convert.ToInt32(split[1]); if (minutes < 7) dminutes = 0.00; else if (minutes < 22) dminutes = 0.25; else if (minutes < 37) dminutes = 0.50; else if (minutes < 53) dminutes = 0.75; else dminutes = 1.0; return decimalTime = dminutes + hours;
-
= ConvertTime(timeArray[x]); } for (int x = 0; x < timeArray.Length; x++) { Console.WriteLine(timeArray[x] + " " + decTimeArray[x]); } Console.ReadKey(); } } public static double ConvertTime(string rawTime) { int hours; int minutes; double dminutes; double decimalTime; string delimStr = ":"; char[] delimiter = delimStr.ToCharArray(); string[] split; split = rawTime.Split(delimiter); hours = Convert.ToInt32(split[0]); minutes = Convert.ToInt32(split[1]); if (minutes < 7) dminutes = 0.00; else if (minutes < 22) dminutes = 0.25; else if (minutes < 37) dminutes = 0.50; else if (minutes < 53) dminutes = 0.75; else dminutes = 1.0; return decimalTime = dminutes + hours;
This was working, but right now I am getting the following error: Expected class, delegate,enum, interface, or struct I am new to c#, and in a class where we are not using the timespan yet, and will not touch on that in this semester. I you could look at the code I have supplied, and maybe help me find the error, that would be great. Thanks :-D
-
This was working, but right now I am getting the following error: Expected class, delegate,enum, interface, or struct I am new to c#, and in a class where we are not using the timespan yet, and will not touch on that in this semester. I you could look at the code I have supplied, and maybe help me find the error, that would be great. Thanks :-D
-
that's cheating. The challenge is to locate the error (and to get someone else to that for you). :)
Luc Pattyn [Forum Guidelines] [My Articles]
Avoiding unwanted divs (as in "articles needing approval") with the help of this FireFox add-in
-
This was working, but right now I am getting the following error: Expected class, delegate,enum, interface, or struct I am new to c#, and in a class where we are not using the timespan yet, and will not touch on that in this semester. I you could look at the code I have supplied, and maybe help me find the error, that would be great. Thanks :-D
From the code you posted and the error you say you are getting, I think your brackets are off. You should have { } wrapped around your class methods (Main and ConvertTime) and also to enclose them.
-
that's cheating. The challenge is to locate the error (and to get someone else to that for you). :)
Luc Pattyn [Forum Guidelines] [My Articles]
Avoiding unwanted divs (as in "articles needing approval") with the help of this FireFox add-in
-
From the code you posted and the error you say you are getting, I think your brackets are off. You should have { } wrapped around your class methods (Main and ConvertTime) and also to enclose them.