Hello, I’m working on this task:
We figured out that there is a spy among us. We don’t know exactly who it is, but we know that all messages that this spy is sending are encoded using the angle between the hands of an analog clock. Your task is to write a program that, given a specific time, returns the angle between the hands of an analog clock showing that time. The input is 2 integers, each written from a new line, that represent hours and minutes (respectively) in the format [0…12] and [0…59]. You should output one number — the smallest angle in degrees between the hands of an analog clock that shows the specified time.
Example 1:
>10
>0
60
**Example 2: **
**>7 **
**>15 **
127.5
Maybe I missed something in the explanation with the angles.
For example between the hours 7 and minutes 15, it should be 120°, not 127.5 ?
Here is my code:
namespace Exam
{
class HandsAngle
{
static void Main()
{
int hours = int.Parse(Console.ReadLine());
int minutes = int.Parse(Console.ReadLine());
// Write your code here
int angleHours = 30*hours;
int angleMinutes = 6*minutes;
int result = Math.Abs(angleHours-angleMinutes);
if(result <= 180)
Console.WriteLine(result);
else
Console.WriteLine(360-result);
}
}
}
Can anyone please help me to solve it?