Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace random
- {
- class Program
- {
- static void Main(string[] args)
- {
- //Define vars
- const double PI = Math.PI;
- int places = 0;
- bool isInt = false;
- Console.Write("PI: Enter number of digits to display, between 1-14: ");
- do
- {
- //Get user input
- string placesAsString = Console.ReadLine();
- try
- {
- places = int.Parse(placesAsString);
- if (places < 0)
- {
- places = 0;
- Console.WriteLine("Cannot use a negative value. Decimal places set to 0.");
- Console.WriteLine("PI at {0} decimal places: {1}", places, Math.Round(PI, places));
- isInt = true;
- }
- else if (places > 14)
- {
- places = 14;
- Console.WriteLine("Cannot use a value over 14. Decimal places set to 14.");
- Console.WriteLine("PI at {0} decimal places: {1}", places, Math.Round(PI, places));
- isInt = true;
- }
- else
- Console.WriteLine("PI at {0} decimal places: {1}", places, Math.Round(PI, places));
- isInt = true;
- }
- catch
- {
- Console.WriteLine("Please enter a valid number");
- }
- } while (!isInt);
- Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement