#Need help with figuring out while loop

1 messages · Page 1 of 1 (latest)

scenic nicheBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

modern jacinth
#

if you want to take input in a loop, you need to put the thing that takes input in a loop

crystal lake
#

No but if user enters 'S', I dont need to loop at all

#

I need to print map then

modern jacinth
#

read the letter separately then

crystal lake
#

yeah i thought of that

#

but ran into a bit of prob with it

#

wait lemme edit and send

#

still how do i get the while loop to work

modern jacinth
#

you still aren't reading the letter again

#

so it's still the same infinite loop or no loop issue

crystal lake
#

but i am reading the letter with scanf

#

Separately

#

oh it might have been because of the space I left before %c

#

i removed it now but its not asking for the input at all

#

like it just says "Create the level" and prints the map without letting the user enter anything

#

oh its a working a bit now

#

Essentially i wrote it as scanf("%c ") now

#

space after %c not before

modern jacinth
#

you aren't changing the value inside the loop, so the loop condition never changes

crystal lake
crystal lake
#

i assigned it to WALL enum

modern jacinth
#

where do you think you're changing the value of W_to_create inside the loop?

crystal lake
#

why do i need to change that

modern jacinth
#

because that's your loop condition jfc

crystal lake
#

doesnt the user just enter a value

#

and if that value is W

#

we run the loop

modern jacinth
#

infinitely

crystal lake
#

if its S, we print map

modern jacinth
#

your loop never stops if it's W

#

you just keep turning thigns into walls over and over until the end of time

crystal lake
#

no actually my loop is only running once

#

it stops automatically after running once

#

no matter what u enter

modern jacinth
#

it does not

crystal lake
#

S or W

crystal lake
modern jacinth
#

so did I

#

and it ran infinitely

#

because the loop condition doesn't change

crystal lake
#

so after assigning it to WALL, should i scanf characters again?

modern jacinth
#

how else would you get new input

#

the wall assignment has nothing to do with your loop condition

#

your loop continues while W_to_create is W. You never change it after reading if the first time, so it will always keep being W, so the loop never stops

crystal lake
#

ohhhh

#

how am I supposed to make it go back tho, I am not rlly sure

modern jacinth
#

go back to what

crystal lake
#

like go back to get another scanf

modern jacinth
#

the things inside your loop happen every loop

#

#287491279888318465 message

#

half an hour ago

crystal lake
#

oh

#

so after the for loop ended

#

i write another scanf

#

to get the char value

#

something like this?

#

instead of writing for loops, should i write while and if statements

crystal lake
#

!solved

scenic nicheBOT
#

Thank you and let us know if you have any more questions!

This thread is now set to auto-hide after an hour of inactivity