with 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.
Here you go:
using System;
class MainClass {
public static void Main (string[] args) {
Console.Write("Enter a number between 0 and 255: ");
int num1, num2, result;
if (!int.TryParse(Console.ReadLine(), out num1))
{
Console.WriteLine("FormatException: Input string was not in a correct format.");
}
Console.Write("Enter another number between 0 and 255: ");
if (!int.TryParse(Console.ReadLine(), out num2))
{
Console.WriteLine("FormatException: Input string was not in a correct format.");
}
result=num1/num2;
Console.WriteLine ("{0} divided by {1} is {2}",num1,num2,result);
}
}
========================================================
A sign of thumbs up would be appreciated.
Get Answers For Free
Most questions answered within 1 hours.