+ 4
cs console ReadLine
when i use Convert.ToInt32(Console.ReadLine()); in order to be able to enter any other value in "sandbox" it shows error. who knows why?
7 odpowiedzi
+ 9
Shura, your code with
x=Convert.ToInt32(Console.ReadLine());
Console.WriteLine (Fact(x));
works fine.
Which error did you get?
The code:
https://code.sololearn.com/c9bWDpLYyf3E/?ref=app
P.S. Песочница - Playground😊
+ 7
The exception "FormatException" can be thrown. Handle it with try... catch.
Here is an example:
int a;
try {
a = Convert.ToInt32(Console.ReadLine());
} catch (FormatException){
Console.ReadLine("Write a number!");
}
It is thrown each time you don't write a number!
+ 6
What is this "sandbox" you're talking about anyways?
(Edit)
Confirmed, "sandbox" = Code Playground ; )
I saw your comment on your factorial code, and inserted
x=Convert.ToInt32(Console.ReadLine());
at line 24 with no problem, I think you need to explain some more. And FYI it is highly recommended to attach the code link when asking a code related question. Do you know how to link your code with the question?
+ 5
The OverflowException can be thrown if the result is greater than 2^32-1.
My tip:
Use Int64 instead!
The StackOverflowException can be thrown if you enter "0".
+ 5
thanks guys. solved
+ 5
Ipang that is playground, as already mentioned by NezhnyjVampir. Sorry for my "french"
+ 4
Shura
I think you are saying you want the program to run even if a user enters something like '5.03' which is considered a decimal.
If this is the case, you have to convert to decimal first and then convert the decimal to an int.
Let me know I miss read your question.
btw- you should provide a link to the code you need help with and it is always a good thing to post the exception you received. Help the community to help you.