Write a program (just console application, no GUI) in C# which prompts the user for an integer, increments the integer by 1 and displays the result in the following format: "The given number n has been incremented to n+1" Make sure your application fails to a secure mode. That is, no matter what is the user input, the application does not terminate with an error
using System; public class IncrementInteger { public static void Main(string[] args) { try { Console.Write("Enter an integer: "); int n = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("The given number " + n + " has been incremented to " + (n+1)); } catch (Exception e) { Console.WriteLine("Invalid input."); } } }
Get Answers For Free
Most questions answered within 1 hours.