c# - Disregard incorrect user input until correct input is received -
i'm having trouble code. have make simple choice game , need have if user inputs invalid option pauses story until choose valid response. tried wrapping whole thing in while(1==1) , entering invalid responses in console window , printed out "that wasn't option" infinitely. how remedy this?? thanks.
// first choice, scene 1 if-statements while (1 == 1) { string firstscene = console.readline(); firstscene = firstscene.trim(); string firstchoice = firstscene.tolower(); console.writeline(); if (firstchoice == "rudely") { assholefactor++; console.writeline(">>\"you're damn right was! we've been working on years. thought you'd happy hours @ office amounted something.\" (douche factor increased)"); break; } if (firstchoice == "nicely") { nicefactor++; console.writeline(">>\"no, wasn't silly. can see you're coming from. suspect there lot of people same type of questions upon release of first model.\" (nice factor increased)"); break; } if (firstchoice == "silence") { judgement--; console.writeline(">>you sip wine , nothing. (judgement decreased)"); break; } if (firstchoice != "rudely" || firstchoice != "nicely" || firstchoice != "silence") { console.writeline("that wasn't option."); continue; } }
you must re-read user input variable within loop before checking it's condition:
var input = readline(); while (true) // or other condition { if (input=="...") { } ... input = readline(); // again }
also, loled @ assholefactor++
Comments
Post a Comment