Mohan S

Mohan S

  • NA
  • 34
  • 38.9k

Check and ensure int value is only numbers

Nov 6 2015 9:47 AM
Hi Guys,
 
I need to check, my int values which am giving as input should be only numerical value.
 
int.Tryparse wont work because am not using a string value.
 
what is the alternate way to get for int value to be numeric.
 
 
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Please enter salary");
int salary = Convert.ToInt32(Console.ReadLine());
 
******* Need to check the SALARY value to be only numeric value and not equal to null also*********
 
int Output = UserProgramCode.Bonus(salary);
Console.WriteLine("Output is: {0}", Output);
Console.ReadLine();
}
class UserProgramCode
{
public static int Bonus(int salary)
{
int b = 0;
if (salary < 0)
{
b = -1;
}
else if (salary > 10000 && salary < 15001)
{
b = 1200 + ((salary * 15) / 100);
}
else
{
b = 500 + ((salary * 8) / 100);
}
}
return b;
}
}

Answers (3)