1.যদি user input হিসেবে "Ten" input দিয়ে থাকে, তাহলে program টি user কে বলে দেবে যে, শুধু Number এরই কেবল যোগ করা সম্ভব।
2. যদি user input হিসেবে অনেক বড় number input দেয়, তাহলে program বলে দেবে যে, Number এর range কত থেকে কত হওয়া উচিত।
using System;
namespace MainPrograms
{
class Program
{
static void Main(string[] args)
{
string strUserChoice = String.Empty;
do
{
try
{
Console.WriteLine("Please enter first number");
int FN = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Please enter second number");
int SN = Convert.ToInt32(Console.ReadLine());
int Total = FN + SN;
Console.WriteLine("Total = {0}", Total);
}
catch (FormatException)
{
Console.WriteLine("Invalid Input, only numbers please.");
}
catch (OverflowException)
{
Console.WriteLine("Only numbers between {0} and {1} are allowed",
Int32.MinValue,Int32.MaxValue);
}
catch (Exception)
{
Console.WriteLine("Unknown problem, please try again");
}
do
{
Console.WriteLine("Do you want to continue - Yes or No");
strUserChoice = Console.ReadLine();
}
while (strUserChoice.ToUpper() != "YES" &&
strUserChoice.ToUpper() != "NO");
}
while (strUserChoice.ToUpper()!="NO");
}
}
}
No comments:
Post a Comment