Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class CompareFloatingPointNumbers
- {
- static void Main()
- {
- double var1;
- double var2;
- Console.WriteLine("Enter var1:");
- if (!double.TryParse(Console.ReadLine(), out var1))
- {
- Console.WriteLine("Invalid input! Please try again!");
- Main();
- }
- Console.WriteLine("Enter var2:");
- if (!double.TryParse(Console.ReadLine(), out var2))
- {
- Console.WriteLine("Invalid input! Please try again!");
- Main();
- }
- bool compare = Math.Abs(var1 - var2) < 0.000001;
- if (compare)
- {
- Console.WriteLine("TRUE! The numbers {0} and {1} are equal with precision of 0.000001!", var1, var2);
- }
- else
- {
- Console.WriteLine("FALSE! The numbers {0} and {1} aren't equal!", var1, var2);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment