Very urgent pls helpC# Operator '>=' cannot be applied to operands of type 'string' and 'int'. | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
0

Very urgent pls helpC# Operator '>=' cannot be applied to operands of type 'string' and 'int'.

this is my code.....pls help me out with it.....thank you string yourAge; Console.WriteLine("what is your age?"); string yourName; Console.WriteLine("what is your Name?"); yourName = Console.ReadLine(); if ( yourAge >= 18) { Console.WriteLine("you are eligible"); } yourAge = Console.ReadLine(); else { Console.WriteLine("sorry"); } but it is coming as; C# Operator '>=' cannot be applied to operands of type 'string' and 'int'

24th Apr 2020, 9:12 AM
Ameya N. Dusane
Ameya N. Dusane - avatar
2 Antworten
+ 2
Thank you very much!!!! :)
25th Apr 2020, 3:45 PM
Ameya N. Dusane
Ameya N. Dusane - avatar
+ 3
Before you test for age, you need to take the input for age. So you should move that line up to the right place. Then, you need to convert the input to an actual number. int age = Convert.ToInt32(yourAge); And then you test this value with your condition. I don't do C#, this is what Google told me. I hope it'll work. 😉
24th Apr 2020, 9:20 AM
HonFu
HonFu - avatar