+ 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."); } } } }

14th Mar 2019, 2:10 PM
CH Ahmad
CH Ahmad - avatar
4 Answers
+ 6
Console.ReadLine() returns string. Convert user input to int. int mark = Convert.ToInt32(Console.ReadLine());
14th Mar 2019, 2:20 PM
Hatsy Rei
Hatsy Rei - avatar
+ 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.
14th Mar 2019, 2:29 PM
Limitless
Limitless - avatar
+ 2
It worked but plez explain why I need to convert even if I was typing in a whole number
14th Mar 2019, 2:26 PM
CH Ahmad
CH Ahmad - avatar