Tech
Forums
Jobs
Books
Events
Live
Interviews
More
Learn
Training
Career
Members
Videos
News
Blogs
Login
Sign Up
Ask Question
3
Reply
Check and ensure int value is only numbers
Mohan S
Nov 6 2015 9:47 AM
368
Reply
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;
}
}
Upload Source Code
Select only zip and rar file.
Post
Reset
Cancel
Answers (
3
)
Next Recommended Forum
database project
TCP String - Always Alive