Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace _04._Control_Flow_and_Loops
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- Console.WriteLine("Please enter the first positive integer: ");
- string firstInput = Console.ReadLine();
- Console.WriteLine("Please enter the second positive integer: ");
- string secondInput = Console.ReadLine();
- int firstNumber = int.MinValue;
- bool isFirstInputParsed = int.TryParse(firstInput, out firstNumber);
- if (isFirstInputParsed)
- {
- Console.WriteLine("First input parsed successfully");
- }
- else
- {
- Console.WriteLine("You have entered something but not an integer");
- Console.WriteLine("You have one more attempt left. Please enter an integer: ");
- firstInput = Console.ReadLine();
- int.TryParse(firstInput, out firstNumber);
- if (firstNumber == 0)
- {
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine("You have no more attempts left. Goodbye.");
- //Console.ForegroundColor = ConsoleColor.Gray;
- Environment.Exit(1);
- }
- }
- int secondNumber;
- bool isSecondInputParsed = int.TryParse(secondInput, out secondNumber);
- Console.WriteLine($"The sum of the two numbers is: {firstNumber + secondNumber}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement