code help
uhhh im trying to run a program that will count how many 1s are in a string of binary, and if its odd or even itll do something, but it just doesnt work?
19 Replies
just doesnt work
it's doing exactly what you told it to
when will this loop end?
oh..
it ends when all the ones have been found i guess
but i have no clue how to add that now that i think about it
nope
it loops forever
i mean
i want it to
do that
but its not
yk
IndexOf finds the index of the first instance of that character in the string, it doesn't keep moving if you keep calling it
i was trying to get it to
count all the 1s in the loop
and
i guess i forgot that it doesnt remove them
uhhh
i think you're overengineering the code a bit, it can be simpler
you can loop over characters in a string directly like
oh visual studio like
suggested that but
idk what var means so i didnt wanna use it
no point if i cant learn from it yk
it's just a shortcut, it's exactly the same as if you typed
char
therealright ill try it
it figures out what the type should be based on the context
like this?
yeah, but you don't need the while loop or the first bit that searches for the first 1
your foreach loop does all that you need to count the 1s in the string
so this should work
oh wait
i need to rename one2
what
uhh
nvm fixed it
t
ty**