Guest User

Untitled

a guest
Dec 12th, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.21 KB | None | 0 0
  1. using System;
  2.  
  3. public class Program
  4. {
  5.     private const Double C = 299792458d; // Speed of light in vacuum
  6.     private const Double N = 1.000292d; // Index of refraction in air
  7.  
  8.     private Double elapsedTime = 0.0d;
  9.     private Double distance = 0.0d;
  10.  
  11.     private static void Main()
  12.     {
  13.         Program prog = new Program();
  14.         prog.Run();
  15.  
  16.         Console.WriteLine("Press Enter to terminate program");
  17.         Console.ReadLine();
  18.     }
  19.  
  20.     public Program() { }
  21.  
  22.     public void Run()
  23.     {
  24.         Console.WriteLine("Speed of light in vacuum: {0}\nIndex of refraction in air (Close to the ground): {1}\n"
  25.             , C, N);
  26.  
  27.         while (true)
  28.         {
  29.             if (this.ReadInput())
  30.             {
  31.                 this.distance = (C * elapsedTime) / (2 * N);
  32.  
  33.                 Console.WriteLine("Result: {0}\n", distance);
  34.  
  35.                 break;
  36.             }
  37.             else
  38.             {
  39.                 Console.WriteLine("Invalid input. Please try again\n");
  40.             }
  41.         }
  42.     }
  43.  
  44.     private Boolean ReadInput()
  45.     {
  46.         Console.WriteLine("Enter elapsed time: ");
  47.  
  48.         return Double.TryParse(Console.ReadLine(), out this.elapsedTime);
  49.     }
  50. }
Add Comment
Please, Sign In to add comment