Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class ThirdDigitCheck
- {
- static void Main()
- {
- int number, divisionBy100, checkForDidit7, digitsCount;
- Console.WriteLine("Enter number with minimum 3 digits:");
- if (int.TryParse(Console.ReadLine(), out number) && number >= int.MinValue && number <= int.MaxValue)
- {
- if (number < 0 && number.ToString().Length >= 4)
- {
- divisionBy100 = (number / 100);
- checkForDidit7 = divisionBy100 % 10;
- Console.WriteLine();
- Console.WriteLine(checkForDidit7 == 7 ? "The third digit of your number {0} is 7" : "The third digit of your number {0} is not 7, it's {1}", number, checkForDidit7);
- Main();
- }
- else if (number > 0 && number.ToString().Length >= 3)
- {
- divisionBy100 = (number / 100);
- checkForDidit7 = divisionBy100 % 10;
- Console.WriteLine(checkForDidit7 == 7 ? "The third digit of your number {0} is 7\n" : "The third digit of your number {0} is not 7, it's {1}\n", number, checkForDidit7);
- Main();
- }
- else
- {
- if(number < 0)
- {
- digitsCount = number.ToString().Length-1;
- }
- else
- {
- digitsCount = number.ToString().Length;
- }
- Console.WriteLine(digitsCount == 1 ? "Your number contains only {0} digit!\n" : "Your number contains only {0} digits!\n", digitsCount);
- Main();
- }
- }
- else
- {
- Console.WriteLine("Invalid input!\n");
- Main();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment