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'
2 Réponses
+ 2
Thank you very much!!!! :)
+ 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. 😉