fbinnzhivko

21.01 Convert Speed Units

May 29th, 2016
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.74 KB | None | 0 0
  1. using System;
  2. class Program
  3. {
  4.     static void Main()
  5.     {
  6.         uint meters = uint.Parse(Console.ReadLine());
  7.         byte hours = byte.Parse(Console.ReadLine());
  8.         byte minutes = byte.Parse(Console.ReadLine());
  9.         byte seconds = byte.Parse(Console.ReadLine());
  10.  
  11.         ushort time = (ushort)(hours * 3600 + minutes * 60 + seconds);
  12.  
  13.         float metersPerSec = (float)meters / time;
  14.         float kilometersPerHour = (float)meters / 1000 / ((float)time / 3600);
  15.         float milesPerHour = (float)meters / 1609/ ((float)time / 3600);
  16.  
  17.         Console.WriteLine("{0:0.#######}", metersPerSec);
  18.         Console.WriteLine("{0:0.#######}", kilometersPerHour);
  19.         Console.WriteLine("{0:0.#######}", milesPerHour);
  20.     }
  21. }
Add Comment
Please, Sign In to add comment