+ 1

help with the code

hello, I need your help, as it turned out earlier, I'm not good at converting types, my code does not work and I do not even have the slightest idea how to fix it thank you in advance https://code.sololearn.com/cF48GVS135rd/?ref=app

4th Nov 2017, 12:36 PM
Serhii
Serhii - avatar
8 Answers
+ 2
There were a few errors, this should work fine: static void Main(string[] args) { Console.WriteLine("Enter password"); int password = Convert.ToInt32(Console.ReadLine()); if (password == 123456) { Console.WriteLine("Access is open"); Console.ReadLine(); } else { Console.WriteLine("Wrong password"); Console.ReadLine(); } }
4th Nov 2017, 1:24 PM
Bagshot
Bagshot - avatar
+ 2
Delete the bool, it's not doing anything.
4th Nov 2017, 12:49 PM
Bagshot
Bagshot - avatar
+ 2
I'm dumb... Many thanks for the explanation, without you, I would not understand what the problem is =) All the best! =)
4th Nov 2017, 1:34 PM
Serhii
Serhii - avatar
+ 1
I should imagine it's because you've named the bool and int the same, so the for loop doesn't know which one to use.
4th Nov 2017, 12:45 PM
Bagshot
Bagshot - avatar
+ 1
but how to make the code working?
4th Nov 2017, 12:47 PM
Serhii
Serhii - avatar
+ 1
unfortunately does not help, there are two more errors cannot implicitly convert type string to int cannot implicitly convert type in to bool https://code.sololearn.com/cF48GVS135rd/?ref=app
4th Nov 2017, 1:10 PM
Serhii
Serhii - avatar
+ 1
If I wasn't on my phone I'd go into more detail but this should help: int password = Convert.ToInt32(Console.ReadLine());
4th Nov 2017, 1:19 PM
Bagshot
Bagshot - avatar
+ 1
I hope after all that has happened you have everything in order with the psyche =)
4th Nov 2017, 1:36 PM
Serhii
Serhii - avatar