How to make string to int
pls help me i needa make a string variable to int variable for my code but i cant figure out how heres my code
24 Replies
what's the problem you're having?
im trying to make what the user types in an interger so i can do like == stuff
but it dont work :(
and i cant figure out
what do you mean by "dont work" you're receiving an error?
when i use variable "Guess" it says i cant use == with Int and String and when i use IntGuess as variable and try to print it nothing comes up
wait
Sorry @cheetahsflame your message contained blocked content and has been removed!
wait i might be dumb hold on
do i use IntGuess or Guess as int variable here
Guess
is declared as a string and can thus only ever hold strings
IntGuess
is declared as an int
.yea ok good thats what i thought
but here its suppose to say a number and if i write the number it says good job but nothing happens so im wondering if IntGuess thing isnt working
how about debugging it?
how
well actually before that, I see a bug
you are doing readline twice
that seems bad, so remove the first one
i did now
ok that fixed it?
for some reason
well yes
so what was happening
is that you were entering a value that was ignored, then it was waiting for a second value
and you didnt know
oh
ok
ReadLine()
halts your application waiting for a string to be given, and only "resumes" after it sees an enter press
since this was happening twice, your program was actually frozenok
thank you
however, you really should learn how to $debug
Tutorial: Debug C# code - Visual Studio (Windows)
Learn features of the Visual Studio debugger and how to start the debugger, step through code, and inspect data in a C# application.
assuming you are using visual studio, this guide should teach you the basics
ok
ill read that some time
good
its a way to see whats going on and what values your variables have etc while the program is running. you can also follow the execution line by line
its extremely handy
oh ok so with debug idont need to print it in my program it does it for me
yeah, instead of
Console.WriteLine(num);
you can just debug to look and see what the value of num isok