我在c ++中偶然发现了一个在线(使用控制台)座位预订系统的源代码。该计划允许人们在飞机上选择头等舱,商务舱和经济舱,选择行,最后选择座位。我一直在尝试重写相同的代码,但在c#但遇到错误,下面是代码:
watchers
// sbyte seat;
static void Main(string[] args)
{
int[,] airplane = new int[13, 6];
sbyte[,] airchar = new sbyte[13, 6];
string ticket;
int[] row = new int[2];
//问题从此处开始
//--------------------------------------------
for (int i = 0; i < 13; i++)
{
for (int j = 0; j < 6; j++)
{
airchar[i, j] = (sbyte)'*';
airplane[i, j] = 0;
}
}
//--------------------------------------------
for (;;)
{
Console.Write("Rows 1 and 2 are first class (FC)");
Console.Write("\n");
Console.Write("Rows 3 through 7 are business class (BC)");
Console.Write("\n");
Console.Write("Rows 8 through 13 are economy class (EC)");
Console.Write("\n");
Console.Write("\n");
Console.Write("* - Available");
Console.Write("\n");
Console.Write("X - Occupied");
Console.Write("\n");
Console.Write("\n");
Console.Write(" \tA\tB\tC\tD\tE\tF");
Console.Write("\n");
Console.Write("Row 1\t");
Console.Write(airchar[0, 0]);
Console.Write("\t");
Console.Write(airchar[0, 1]);
Console.Write("\t");
Console.Write(airchar[0, 2]);
Console.Write("\t");
Console.Write(airchar[0, 3]);
Console.Write("\t");
Console.Write(airchar[0, 4]);
Console.Write("\t");
Console.Write(airchar[0, 5]);
Console.Write("\n");
Console.Write("Row 2\t");
Console.Write(airchar[1, 0]);
Console.Write("\t");
Console.Write(airchar[1, 1]);
Console.Write("\t");
Console.Write(airchar[1, 2]);
Console.Write("\t");
Console.Write(airchar[1, 3]);
Console.Write("\t");
Console.Write(airchar[1, 4]);
Console.Write("\t");
Console.Write(airchar[1, 5]);
Console.Write("\n");
Console.Write("Row 3\t");
Console.Write(airchar[2, 0]);
Console.Write("\t");
Console.Write(airchar[2, 1]);
Console.Write("\t");
Console.Write(airchar[2, 2]);
Console.Write("\t");
Console.Write(airchar[2, 3]);
Console.Write("\t");
Console.Write(airchar[2, 4]);
Console.Write("\t");
Console.Write(airchar[2, 5]);
Console.Write("\n");
Console.Write("Row 4\t");
Console.Write(airchar[3, 0]);
Console.Write("\t");
Console.Write(airchar[3, 1]);
Console.Write("\t");
Console.Write(airchar[3, 2]);
Console.Write("\t");
Console.Write(airchar[3, 3]);
Console.Write("\t");
Console.Write(airchar[3, 4]);
Console.Write("\t");
Console.Write(airchar[3, 5]);
Console.Write("\n");
Console.Write("Row 5\t");
Console.Write(airchar[4, 0]);
Console.Write("\t");
Console.Write(airchar[4, 1]);
Console.Write("\t");
Console.Write(airchar[4, 2]);
Console.Write("\t");
Console.Write(airchar[4, 3]);
Console.Write("\t");
Console.Write(airchar[4, 4]);
Console.Write("\t");
Console.Write(airchar[4, 5]);
Console.Write("\n");
Console.Write("Row 6\t");
Console.Write(airchar[5, 0]);
Console.Write("\t");
Console.Write(airchar[5, 1]);
Console.Write("\t");
Console.Write(airchar[5, 2]);
Console.Write("\t");
Console.Write(airchar[5, 3]);
Console.Write("\t");
Console.Write(airchar[5, 4]);
Console.Write("\t");
Console.Write(airchar[5, 5]);
Console.Write("\n");
Console.Write("Row 7\t");
Console.Write(airchar[6, 0]);
Console.Write("\t");
Console.Write(airchar[6, 1]);
Console.Write("\t");
Console.Write(airchar[6, 2]);
Console.Write("\t");
Console.Write(airchar[6, 3]);
Console.Write("\t");
Console.Write(airchar[6, 4]);
Console.Write("\t");
Console.Write(airchar[6, 5]);
Console.Write("\n");
Console.Write("Row 8\t");
Console.Write(airchar[7, 0]);
Console.Write("\t");
Console.Write(airchar[7, 1]);
Console.Write("\t");
Console.Write(airchar[7, 2]);
Console.Write("\t");
Console.Write(airchar[7, 3]);
Console.Write("\t");
Console.Write(airchar[7, 4]);
Console.Write("\t");
Console.Write(airchar[7, 5]);
Console.Write("\n");
Console.Write("Row 9\t");
Console.Write(airchar[8, 0]);
Console.Write("\t");
Console.Write(airchar[8, 1]);
Console.Write("\t");
Console.Write(airchar[8, 2]);
Console.Write("\t");
Console.Write(airchar[8, 3]);
Console.Write("\t");
Console.Write(airchar[8, 4]);
Console.Write("\t");
Console.Write(airchar[8, 5]);
Console.Write("\n");
Console.Write("Row 10\t");
Console.Write(airchar[9, 0]);
Console.Write("\t");
Console.Write(airchar[9, 1]);
Console.Write("\t");
Console.Write(airchar[9, 2]);
Console.Write("\t");
Console.Write(airchar[9, 3]);
Console.Write("\t");
Console.Write(airchar[9, 4]);
Console.Write("\t");
Console.Write(airchar[9, 5]);
Console.Write("\n");
Console.Write("Row 11\t");
Console.Write(airchar[10, 0]);
Console.Write("\t");
Console.Write(airchar[10, 1]);
Console.Write("\t");
Console.Write(airchar[10, 2]);
Console.Write("\t");
Console.Write(airchar[10, 3]);
Console.Write("\t");
Console.Write(airchar[10, 4]);
Console.Write("\t");
Console.Write(airchar[10, 5]);
Console.Write("\n");
Console.Write("Row 12\t");
Console.Write(airchar[11, 0]);
Console.Write("\t");
Console.Write(airchar[11, 1]);
Console.Write("\t");
Console.Write(airchar[11, 2]);
Console.Write("\t");
Console.Write(airchar[11, 3]);
Console.Write("\t");
Console.Write(airchar[11, 4]);
Console.Write("\t");
Console.Write(airchar[11, 5]);
Console.Write("\n");
Console.Write("Row 13\t");
Console.Write(airchar[12, 0]);
Console.Write("\t");
Console.Write(airchar[12, 1]);
Console.Write("\t");
Console.Write(airchar[12, 2]);
Console.Write("\t");
Console.Write(airchar[12, 3]);
Console.Write("\t");
Console.Write(airchar[12, 4]);
Console.Write("\t");
Console.Write(airchar[12, 5]);
Console.Write("\n");
Console.Write("\n");
语法错误出现在 ConsoleInput.ReadToWhiteSpace(true); 表示ticket,row [0]和seat。另外发生的另一个错误是在switch语句中,所有情况都突出显示并且状态&#34; 无法隐式转换类型&#39; char&#39;到了&#39; sbyte&#39;。存在显式转换(您是否错过了演员?)&#34;
如果有人能帮助我,我将非常感激。谢谢!
答案 0 :(得分:-1)
在开关中你有座位,这是sbyte和万一你的情况。所以要么将每个char转换为sbyte
或return
char
来自方法ReadToWhiteSpace
。
最好您可以使用Console.ReadLine()
或Console.Read()
(给出ASCII值)而不是ConsoleInput.ReadToWhiteSpace
来从控制台获取输入。