Hello, I am trying out different ways to receive int number from user. If the input is not an int number, it gives out an error message.
But I seem to be getting error messages on the highlighted parts.
"Since ___________ Returns a void, a return keyword must not be followed by an object expression "
public static void FirstInput()
{
do
{
fromF = 0;
if (int.TryParse(Console.ReadLine(), out fromF))
{
return fromF;
}
Console.WriteLine("Error");
{
return FirstInput();
}
}
}
Thanks for the help!

MahaRank #2,573 · 543 reputationPosted Oct 19, 2014, 5:04 PM EDT
namespace IntergerNumber
{
class Program
{
static void Main(string[] args)
{
Console.Write("Input an integer number ");
int i;
bool trueORfaulse = int.TryParse(Console.ReadLine(), out i );
outerUp:
while(trueORfaulse == false)
{
Console.Write("\nThis is not an integer number, try again ");
trueORfaulse = int.TryParse(Console.ReadLine(), out i);
}
while (trueORfaulse == true)
{
Console.Write("\nInput an integer number ");
trueORfaulse = int.TryParse(Console.ReadLine(), out i);
if (trueORfaulse == false) goto outerUp;
}
Console.ReadKey();
}
}
}
Wim SturkenboomRank #2,527 · 554 reputationPosted Oct 19, 2014, 10:02 PM EDT
public static void FirstInput()
Change the definition to below
public static int FirstInput()
Riddhi ValechaRank #794 · 2.9K reputationPosted Oct 21, 2014, 1:22 AM EDT
You can use javascript function to check whether the input is numeric or not.
Eg-
In aspx page,
-------------------
----------------------
In this case, user will be able to type only numbers and nothing else.
Also, the lines of code will be reduced.
Wim SturkenboomRank #2,527 · 554 reputationPosted Oct 21, 2014, 10:38 AM EDT
You can use javascript function to check whether the input is numeric or not.
[/quote]
In a console application ??
Song Lee49 reputationPosted Oct 23, 2014, 3:32 PM EDT