This content is not currently approved and is visible here for review only.

Library code snippets

Find the value between the hands of a Clock in degrees...

Angle betwee hands in a clock

///

<summary>

/// Calculates the degrees between the hours and the minutes hand

/// </summary>

/// <param name="hours"> hours </param>

/// <param name="minutes"> minutes </param>

/// <returns> degrees </returns>

public static double ConvertToDegrees( int hours, int minutes)

{

try

{

/*

* the formula to calculate the degrees between a hour and minute hand is

* 30H - (11/2)M where H - hours and M - minutes

*/

if (hours < 1 || hours>12)

throw new Exception("Hours cannot be less than 1 or greater than 12");

//check if minutes value lies in the range 0 - 59

if (minutes < 0 || minutes > 59)

throw new Exception("Minutes cannot be less than 0 or greater than 59");

double deg = (( double )(30*hours) - ( double )((11*minutes)/2) );

return deg;

}

catch (Exception ex)

{

throw ex;

}

}

Comments

  1. 01 Jan 1999 at 00:00

Leave a comment

Sign in or Join us (it's free).

AddThis

Related podcasts

  • Looking into the C# Crystal Ball with Charlie Calvert and Bill Wagner

    One of the most exciting announcements from PDC was the news about C# 4.0 and Visual Studio 2010. With all the excitement and discussion throughout the event about these new developer tools, we reached out to two experts in the fields. Charlie Calvert and Bill Wagner sat down with Keith and Woody...

Events coming up

  • Dec 6

    Developing AJAX Web Applications with Castle Monorail

    London, United Kingdom

    Monorail is the model-view-controller engine of the Castle Project, bringing many of the best ideas of Ruby on Rails to the .NET world. In this talk, David De Florinier and Gojko Adzic show how Monorail makes it easy to develop .NET based AJAX applications, and how to use the Castle Project to build Web 2.0 applications effectively. Come to this session if you are a .NET web developer. Everyone is welcome!