The method WriteLine()
has as return void
, ie returns nothing, then has no value in the execution of it, and is trying to store a value in the variable, this is not possible, need to use a method that returns some value to be able to store in the variable, and in the specific case has to be a type int
, so I could not indicate the ReadLine()
also that returns a string
.
But what you want seems to be for someone to type something, the question is not clear on this and without understanding the problem becomes complicated to find a suitable solution, I will guess that it is this. Then you’ll have to use the ReadLine()
to take the typed data, convert it to int
safely and then you can use in the desired calculation, luckily this is one of the exercises that people post most here and has a lot of code that you can see how is the right.
Of course you will only learn if you understand what each thing does, so it would be good to do new research on the subject, right here on the site there is a lot, and if you do not have can ask a new more specific questions.
I’m not going to put the code here because it doesn’t make sense to put another example of how to use the ReadLine()
in the right way has a huge amount of questions that this has already been demonstrated and would even make the question as duplicate if it went this way:
Possible duplicate of Doubt Console.Readline
– novic