Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- public class Program
- {
- private const Double C = 299792458d; // Speed of light in vacuum
- private const Double N = 1.000292d; // Index of refraction in air
- private Double elapsedTime = 0.0d;
- private Double distance = 0.0d;
- private static void Main()
- {
- Program prog = new Program();
- prog.Run();
- Console.WriteLine("Press Enter to terminate program");
- Console.ReadLine();
- }
- public Program() { }
- public void Run()
- {
- Console.WriteLine("Speed of light in vacuum: {0}\nIndex of refraction in air (Close to the ground): {1}\n"
- , C, N);
- while (true)
- {
- if (this.ReadInput())
- {
- this.distance = (C * elapsedTime) / (2 * N);
- Console.WriteLine("Result: {0}\n", distance);
- break;
- }
- else
- {
- Console.WriteLine("Invalid input. Please try again\n");
- }
- }
- }
- private Boolean ReadInput()
- {
- Console.WriteLine("Enter elapsed time: ");
- return Double.TryParse(Console.ReadLine(), out this.elapsedTime);
- }
- }
Add Comment
Please, Sign In to add comment