2
Answers

if,return method

Ask a question
Song Lee

Song Lee

9y
739
1
 Hi, I was wondering if there a way to make it so if something other than int or double is input, it gives an error message.
This is what I got so far: 
 
public static void FirstInput()
{
Console.WriteLine("F to C");
Console.Write("Enter number : ");
double.TryParse(Console.ReadLine(), out fromF);
}
 
//and below is the coding that I got from a friend 
Is there a way to integrate those two codes? 

if (int.tryParse(Console.ReadLine(), out res))

return res;

console.WriteLine("Error, can't convert, try again");

return GetInteger();

 
 
Thank you! 
 

Answers (2)