Question

Write a program (just console application, no GUI) in C# which prompts the user for an...

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

Homework Answers

Answer #1
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.");
        }
    }
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a python program that does the following: Prompts the user for three numbers in one...
Write a python program that does the following: Prompts the user for three numbers in one request. Be sure to specify the “delimiter” by which a user enters those three numbers. Divides the first number by the second number and add that result to the third number. Prints output that shows in one line the formula applied and the result of the calculation. Validate input by: •    Checking the user entered 3 values •    Appropriately checking for the following errors:...
Write a program that prompts the user to enter an integer number between 1 and 999....
Write a program that prompts the user to enter an integer number between 1 and 999. The program displays the sum of all digits in the integer if the input is valid; otherwise, it displays a message indicating that the integer is not between 1 and 999 and hence, is invalid. Name the program file Q1.cpp Example: if the user enters 12, sum of digits is 3. If the user enters 122, sum of digits is 5.
Write an application that prompts a user for two integers and displays every integer between them....
Write an application that prompts a user for two integers and displays every integer between them. Display There are no integers between X and Y if there are no integers between the entered values. Make sure the program works regardless of which entered value is larger. This is a java assignment. Pls help
Write an application that prompts a user for two integers and displays every integer between them....
Write an application that prompts a user for two integers and displays every integer between them. Display There are no integers between X and Y if there are no integers between the entered values. Make sure the program works regardless of which entered value is larger. ------------------------------------------------------------------------------------------------- import java.util.Scanner; public class Inbetween {     public static void main (String args[]) {         // Write your code here     } }
In Python only. Write a program that prompts the user to enter a hex character and...
In Python only. Write a program that prompts the user to enter a hex character and displays its corresponding decimal integer.
[JAVA] Write a program that prompts the user for an integer and displays if the provided...
[JAVA] Write a program that prompts the user for an integer and displays if the provided integer is a prime number or not. A prime number is a number that is divisible only by 1 and itself. First few prime numbers are 2,3,5,7,11,13 and so on. [using if-statements, and if-else-statement ]
4.29 (Square of Asterisks) Write an application that prompts the user to enter the size of...
4.29 (Square of Asterisks) Write an application that prompts the user to enter the size of the side of a square, then displays a hollow square of that size made of asterisks. Your program should work for squares of all side lengths between 1 and 20. I keep getting the error: "AsteriskSquare.java:2: error: class Main is public, should be declared in a file named Main.java public class Main ^ 1 error"
Write a program that prompts the user to input a decimal number and outputs the number...
Write a program that prompts the user to input a decimal number and outputs the number rounded to the nearest integer.
Write a program that prompts the user for a measurement in meters and then converts it...
Write a program that prompts the user for a measurement in meters and then converts it to miles, feet, and inches. Again, check for valid input and exit with an error msg if you don’t get it. Testing: use some known values here and watch for integer truncation. This should be in javascript and should execute in netbeans.
Q1) Write a program that prompts the user to input an integer that represents cents.The program...
Q1) Write a program that prompts the user to input an integer that represents cents.The program will then calculate the smallest combination of coins that the user has. For example, 27 cents is 1 quarter and 2 pennies. Note : given $bills the change should come has to run from pycharm.