In: Computer Science
C#
Create a console application that asks the user for two numbers in the range 0-255 and then divides the first number by the second: Enter a number between 0 and 255: 100 Enter another number between 0 and 255: 8 100 divided by 8 is 12 Enter a number between 0 and 255: apples Enter another number between 0 and 255: bananas FormatException: Input string was not in a correct format.
input code:
output:
code:
using System;
class HelloWorld {
static void Main()
{
/*make a try catch*/
try
{
/*take user input*/
Console.Write("Enter a number between 0 and 255: ");
string first=Console.ReadLine();
Console.Write("Enter another number between 0 and 255: ");
string second=Console.ReadLine();
/*print output*/
Console.WriteLine("{0} divided by {1} is
{2}",first,second,Int32.Parse(first)/Int32.Parse(second));
}
catch(Exception e)
{
/*print this is Exception occurs*/
Console.WriteLine("{0}: Input string was not in a correct
format.",e.GetType().Name);
}
}
}