I need help using arrays with a switch statement in them. I need to use a one dimensional array of type bool to represent a seating chart of 1-10. (1-5 = a ) (6-10 = b )
1
Expert's answer
2011-10-27T10:51:08-0400
using System; using System.Collections.Generic; using System.Linq; using System.Text;
namespace RepresentaSeatingChart { class Program { static int[] SeatingChart = new int[10]; static bool[] SeatingChartbool = new bool[10]; static bool a = true; static bool b = false; static void Main(string[] args) { for (int i = 0; i < 10; i++) { SeatingChart[i] = i+1; } for (int i = 0; i < 10; i++) { switch(SeatingChart[i]){ case 1: SeatingChartbool[i] = a; break; case 2: SeatingChartbool[i] = a; break; case 3: SeatingChartbool[i] = a; break; case 4: SeatingChartbool[i] = a; break; case 5: SeatingChartbool[i] = a; break; case 6: SeatingChartbool[i] = b; break; case 7: SeatingChartbool[i] = b; break; case 8: SeatingChartbool[i] = b; break; case 9: SeatingChartbool[i] = b; break; case 10: SeatingChartbool[i] = b; break; }
} for (int i = 0; i < 10; i++) { Console.WriteLine("Number " + SeatingChart[i] + " = " + SeatingChartbool[i].ToString()); }
Comments
Leave a comment