+ 1
Why it isn't working?Plez help
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SoloLearn { class Program { static void Main(string[] args) { int mark; mark = Console.ReadLine(); if (mark < 50) { Console.WriteLine("You failed."); } else { Console.WriteLine("You passed."); } } } }
4 Answers
+ 6
Console.ReadLine() returns string. Convert user input to int.
int mark = Convert.ToInt32(Console.ReadLine());
+ 4
CH Ahmad Console.ReadLine() reads the user's input.
Now when you do an input it will most likely be in String format.
Because if this, you will need to convert it to an Int, or other variable type.
+ 2
It worked but plez explain why I need to convert even if I was typing in a whole number