0

Whats wrong with my code?

using System; using System.IO; using System.Linq; using System.Collections.Generic; namespace CSharp_Shell { public static class Program { public static void Main(string[]args) { Console.WriteLine("Enter your age"); int a; a= Console.ReadLine(); if(a<18){ Console.WriteLine("Not permitted"); }} } }

17th Dec 2020, 5:52 AM
Morteza Mohammadi
Morteza Mohammadi - avatar
4 RĂ©ponses
+ 2
You need to convert Console.ReadLine() to int with Int32.Parse(). Becomes Int32.Parse(Console.ReadLine())
17th Dec 2020, 6:02 AM
äœ çŸ„é“èŠć‰‡ïŒŒæˆ‘äčŸæ˜Ż
äœ çŸ„é“èŠć‰‡ïŒŒæˆ‘äčŸæ˜Ż - avatar
0
Why to convert?
17th Dec 2020, 6:15 AM
Morteza Mohammadi
Morteza Mohammadi - avatar
0
It worked. Thanks.
17th Dec 2020, 6:15 AM
Morteza Mohammadi
Morteza Mohammadi - avatar
0
It also wirks by this method... a= int.Parse(Console.ReadLine());
17th Dec 2020, 6:19 AM
Morteza Mohammadi
Morteza Mohammadi - avatar