c# - How can I make the same code repeat until the player answers differently? -


so trying make text adventure game computer class. know basics of c# i'm missing because can't code right. want make man ask player question if answer no repeats question because have answer yes game continue. tried using loop didn't work well. anyways, code have:

using system; using system.collections.generic; using system.linq; using system.text;  namespace consoleapplication1 {     class program     {         static void main(string[] args)         {             console.writeline("minecraft text adventure: part 1!");             console.writeline("\"hello traveller!\" says man. \"what's name?\"");             string playername = console.readline();             console.writeline("\"hi " + playername + ", welcome minecraftia!\ni give tour of our little town there isn't left to\nsee since attack.\"");             console.writeline("he looks @ stone sword in hand. \"could defeat zombies in hills , bring peace our land?\"");             string answer1 = console.readline();             if (answer1 == "yes")             {                 console.writeline("\"oh, many " + playername + "!\"");                 answernumber = 2;             }             else if (answer1 == "no")             {                 console.writeline("\"please " + playername + "! need help!\"\n\"will us?\"");                 answernumber = 1;             }             else             {                 console.writeline("pardon me?");                 answernumber = 0;             }             (int answernumber = 0; answernumber < 2;)             {                 console.writeline("\"we need help!\"\n\"will us?\"");             }         }     } } 

any or suggestions appreciated because i've run out of ideas.

i think best bet use while loop, check out msdn example guide

using system; public class testdowhile  {     public static void main ()      {         int x = 0;                  {             console.writeline(x);             x++;         } while (x < 5);     } } 

Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -