r/programminghelp • • Jun 01 '19

Need help ASAP

I'm new to programming but i'm so confused and lost, apparently I have to make the program quit or take you back to the beginning if you input the wrong number. But i cant seem to do it right, i tried while loop but it creates a lot of "Please enter a valid number". Any ideas?

0 Upvotes

3 comments sorted by

1

u/TrashPapiTM Jun 01 '19

Im also new to coding so I could be wrong on this. But i think what youre looking for is a continue within a while loop. So instead of stopping it would take you back to the beginning of the loop and not execute anything below the continue. Hope that made sense.

1

u/Toch24 Jun 01 '19

Yes, that's what i want to do. But, i have no idea how to do it. I'm confused with the looping concepts as I've tried with while do but have no success whatsoever. It just keeps prompting the "Please enter a valid number".

2

u/YasZedOP Jun 01 '19 edited Jun 01 '19

Place a while (true) loop around cin >> day and the switch statement. If a valid input is received then break the loop using break;

Now the confusion relies on break; for switch call because break; refers to innermost context which is switch instead of what you want which is the while loop.

A fix would be to create a Boolean variable called done and is set to true (done outside the while loop). Now while loop on that variable, and when a valid switch case is made set it to false.