Please bare with me as this is my first little tutorial and first time explaining it, please XAV or Jordan or whoever else if i dont make sense or mistaken something, please correct, this is also great to learn any additional info I have missed.
namespace ConsoleApplication1 { class Program { static void Main() { string inputfirst = ""; string inputlast = ""; string choice = ""; begin: Console.WriteLine("Hello what is your First name?"); inputfirst = Console.ReadLine(); Console.WriteLine("and what is your last name?"); inputlast = Console.ReadLine(); Console.WriteLine("Hello " + inputfirst + inputlast); decide: Console.WriteLine("what would you like to do? continue or quit?"); choice = Console.ReadLine(); if (choice == "continue") { goto begin; } if (choice == "quit") { Console.WriteLine("Good Bye"); System.Threading.Thread.Sleep(3000); } else { Console.WriteLine("please enter continue or quit"); goto decide; } } } }
Ok so here is the program, the purpose of this is to ask the user for input then it shoots back out user input but also asks if you want to repeat the program without restarting the program. So first is variable and variable type, string and the strings are inputfirst = first name which asks you: Console.WriteLine("Hello what is your First name?");
inputfirst = Console.ReadLine();
The second user input is the inputlast = user last name = inputlast = Console.ReadLine();
Console.WriteLine("Hello " + inputfirst + inputlast);
but also you see another string called "choice" which happens to be between the word decide: but also you see another word at the beginning called begin: notice it does not have a ; but a : which i hope jordan or Xav or someone can explain in detail but i would say just think of the decide/begin as a bookmarks in a book to reference or go back to your place to re-read etc. so moving on after it tells your first and last name it then asks you a choice which here comes the if and else statements, if choice (<-- string declared earlier) is equal (==) to the word "continue" or someone types it in as to what they want, then perform whatever is inside {} which is but if the user types quit then do what it says in {}, the last thing is what ever is the user inputs then do this. Now the goto as i said is like book marks and it has a part to play in the if/if/else, so if this happens, the goto (self explanatory) this book mark of the book (or program) but make sure you have the : instead of ; which i was having trouble with in the beginning. The last thing is System.Threading.Thread.Sleep(3000); which is thanks to Xav for telling me that means just end the program in .... uhh... is that seconds or miliseconds? .. Well i hope this helps out
Edited by Jordan, 24 July 2008 - 03:52 PM.
Added code tags