Guest User

Untitled

a guest
Aug 20th, 2018
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.71 KB | None | 0 0
  1. Variables reset to zero when I call a method
  2. using System;
  3.  
  4. namespace Assignment7
  5. {
  6. class Plane
  7. {
  8. public static void Main(string[] args)
  9. {
  10. Console.WriteLine("Welcome to the Airline Reservation System.");
  11. Console.WriteLine("Where would you like to sit?n");
  12. Console.WriteLine("Enter 1 for First Class.");
  13. Console.WriteLine("Enter 2 for Economy.");
  14. CheckIn();
  15. }
  16.  
  17. public static void CheckIn()
  18. {
  19. int choice = Convert.ToInt32(Console.ReadLine());
  20. int firstClass = 0;
  21. int economy = 0;
  22.  
  23. if (choice == 1)
  24. {
  25. do
  26. {
  27. Console.WriteLine("You have chosen a First Class seat.");
  28. firstClass++;
  29. CheckIn();
  30. } while (firstClass < 5);
  31. }
  32. else if (choice == 2)
  33. {
  34. do
  35. {
  36. Console.WriteLine("You have chosen an Economy seat.");
  37. economy++;
  38. CheckIn();
  39. } while (economy < 5);
  40. }
  41. else
  42. {
  43. Console.WriteLine("That does not compute.");
  44. CheckIn();
  45. }
  46. }
  47. }
  48. }
  49.  
  50. int firstClass = 0;
  51.  
  52. static int firstClass = 0;
  53.  
  54. using System;
  55.  
  56. namespace Assignment7
  57. {
  58. class Plane
  59. {
  60. public static void Main(string[] args)
  61. {
  62. Console.WriteLine("Welcome to the Airline Reservation System.");
  63. Console.WriteLine("Where would you like to sit?n");
  64. Console.WriteLine("Enter 1 for First Class.");
  65. Console.WriteLine("Enter 2 for Economy.");
  66. CheckIn(0, 0);
  67. }
  68.  
  69. public static void CheckIn(int firstClassSeatsTaken, int economySeatsTaken)
  70. {
  71. int choice = Convert.ToInt32(Console.ReadLine());
  72.  
  73. if (choice == 1)
  74. {
  75. do
  76. {
  77. Console.WriteLine("You have chosen a First Class seat.");
  78. firstClass++;
  79. CheckIn(firstClassSeatsTaken, economySeatsTaken);
  80. } while (firstClass < 5);
  81. }
  82. else if (choice == 2)
  83. {
  84. do
  85. {
  86. Console.WriteLine("You have chosen an Economy seat.");
  87. economy++;
  88. CheckIn(firstClassSeatsTaken, economySeatsTaken);
  89. } while (economy < 5);
  90. }
  91. else
  92. {
  93. Console.WriteLine("That does not compute.");
  94. CheckIn(firstClassSeatsTaken, economySeatsTaken);
  95. }
  96. }
  97. }
  98. }
Add Comment
Please, Sign In to add comment