+ 1
C# help
Hi everyone. I’ m trying to remix a calculator in C# and I use this script : float number1 = Console.ReadLine(); float number2 = Console.ReadLine(); Console.WriteLine(number1 + number2); But the console say an error
2 ответов
+ 5
Just some examples from Code Playground, you can search there for more examples to learn from 👍
https://code.sololearn.com/cPmnEkC8OWqz/?ref=app
https://code.sololearn.com/cj9k3AxV1xau/?ref=app
+ 2
Console.ReadLine(); returns a string.
You cannot assign a string to a float.
You need to convert that number with
float number1 = float.Parse(Console.ReadLine());
Be carefull some people use
, (comma) as decimal separator
other use
. (dot) as decimal separator