Guest User

Untitled

a guest
Oct 21st, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. IDictionary<string, int> dict = new Dictionary<string, int>(); // where you would store all
  2. // the answers
  3.  
  4. String prompt1 = "Enter a number ...";
  5. String prompt2 = "Enter number of IPv4 ..."; // and so on
  6.  
  7. // initialize your stack
  8. Stack<string> prompts= new Stack<string>();
  9. prompts.Push(prompt1);
  10. prompts.Push(prompt2);
  11.  
  12. while(prompts.Count != 0){
  13. String prompt = prompts.Peek(); // this doesn't remove the element from stack
  14. int input = 0;
  15.  
  16. //display prompt to user and get input in input variable
  17.  
  18. if(input>0){ // or whatever validation logic you want
  19. dict.Add(prompt, input);
  20. prompts.Pop(); //removes topmost element
  21. }
  22. }
  23.  
  24. class Program
  25. {
  26. static void Main(string[] args)
  27. {
  28. int instances = CheckValues("Number of instances");
  29. int numofIpv4 = CheckValues("number of ipv4");
  30. int numofIpv6 = CheckValues("number of ipv6");
  31. //etc
  32. }
  33.  
  34. private static int CheckValues(string input)
  35. {
  36. int parserValue = 0;
  37. string enteredValue = string.Empty;
  38. do
  39. {
  40. Console.WriteLine(input);
  41. enteredValue = Console.ReadLine();
  42. }
  43. while (!Int32.TryParse(enteredValue, out parserValue) || parserValue == 0);
  44. return parserValue;
  45. }
  46. }
  47.  
  48. Regex _ipv4Regex = new Regex(@"bd{1,3}.d{1,3}.d{1,3}.d{1,3}b");
  49. if (ip.Matches(input))
  50. {
  51. // if valid
  52. }
Add Comment
Please, Sign In to add comment