C++ Can';t输出可用和已占用的座位

C++ Can';t输出可用和已占用的座位,c++,C++,因此,我正在制作一个飞机座位程序,我希望我的用户输入一个数字来选择一行,并输入一个字母来选择一行中六个选项中的一个(a到F)。我还希望用户只要输入字母“C”,就可以继续输入座位。我已经编写了大部分代码,但由于某些原因,无法将其输出。在第一次初始化和显示座椅后,座椅没有输出。程序刚刚停止。我试图在纠正我在逻辑中犯的任何错误之前输出结果 //Any unused includes are part of the default code #include <iostream> #inc

因此,我正在制作一个飞机座位程序,我希望我的用户输入一个数字来选择一行,并输入一个字母来选择一行中六个选项中的一个(a到F)。我还希望用户只要输入字母“C”,就可以继续输入座位。我已经编写了大部分代码,但由于某些原因,无法将其输出。在第一次初始化和显示座椅后,座椅没有输出。程序刚刚停止。我试图在纠正我在逻辑中犯的任何错误之前输出结果

//Any unused includes are part of the default code

#include <iostream>
#include <ctime>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cassert>

using namespace std;

const int rowsz = 5;
const int colsz = 6;

int main()
{
    char seating[rowsz][colsz];
    char y = ' '; //Row
    char x = ' '; //Col
    char taken = 'X'; // This letter is for marking booked seats
    char letter = ' '; // This letter initializes the seat positions.
    char let = ' '; // Choice for a seat
    char choice = 'c'; // This let's the user quit or continue booking seats
    int rownum = 1; // Row number
    for(int row = 1; row <= rowsz; row++)
    {
        letter = 'A';
        cout << rownum;
        rownum++;
        for(int col = 0; col < colsz; col++)
        {
            seating[row][col] = letter;
            letter++;
            cout << seating[row][col];
        }
        cout << endl;
    }
    cout << "Would you like to get a seat? Press C. TO quit, press Q: "; cin >> choice;
    while(toupper(choice) == 'C')
    {
        cout << "Enter a row. Ex: 1,2,3... ";cin >> y;
        cout << "Enter a Letter for a seat: "; cin >> x;

        if(toupper(x) == 'A')
            x = 0;
        if(toupper(x) == 'B')
            x = 1;
        if(toupper(x) == 'C')
            x = 2;
        if(toupper(x) == 'D')
            x = 3;
        if(toupper(x) == 'E')
            x = 4;
        if(toupper(x) == 'F')
            x = 5;

        seating[y][x] = taken;

        for(int row = 1; row <= rowsz; row++)
        {
            for(int col = 0; col < colsz; col++)
            {
                cout << seating[row][col];
            }
            cout << endl;
        }
        cout << "Seat again? Press C to continue to seat and press Q to quit. "; cin >> choice;
    }
    if(toupper(choice) != 'C')
    {
        cout << "Thank you for using this program! " << endl;
    }

    return 0;
}
//任何未使用的include都是默认代码的一部分
#包括
#包括
#包括
#包括
#包括
#包括
使用名称空间std;
常量int rowsz=5;
常数int colsz=6;
int main()
{
木炭座椅[rowsz][colsz];
字符y='';//行
char x='';//列
char take='X';//此字母用于标记已预订的座位
char letter='';//此字母初始化座椅位置。
char let='';//座位选择
char choice='c';//让用户退出或继续预订座位
int rownum=1;//行数

对于(int行=1;行<P>)而不是交接代码,我认为更有益的是覆盖一些关于如何调试这种情况的基础知识,而不是一下子查看整个程序,试着把它分解成碎片,直到发现代码的哪个部分有问题。(暗示,暗示,暗示):

while(toupper(choice)='C')
{
cout>y;
cout>x;
if(toupper(x)='A')
x=0;
if(toupper(x)='B')
x=1;
if(toupper(x)='C')
x=2;
if(toupper(x)='D')
x=3;
if(toupper(x)='E')
x=4;
if(toupper(x)='F')
x=5;
座位[y][x]=已就座;

for(int row=1;row a array
T array[N];
的有效索引从
0
N-1
for(int row=1;row
for(int row=0;row
如果使用ASCII编码,可以将
If
语句简化为
x=toupper(x)-“A”;
。建议:使用变量名
,而不是
y
x
。名称
使代码更易于阅读(它们只会为编译增加微不足道的时间)。您将
x
'A'
转换为
'F'
0
转换为
5
。您错过了与
y
类似的操作。
'1'
的值是
49
,但您想将其用作数组的索引…将
都更改为(int row=1;row I没有向下投票(尚未;)但是…当打印时,打印
y
会有什么帮助呢?哈哈哈,非常感谢您(现在;)的克制。我想我的观点可能被忽略了,OPs代码有很多问题。我认为对他来说,把它分解成小部分,看看代码的每一步都在做什么会更有价值。我的意思不仅仅是“y”,而是更多地将所有内容转储到控制台,看看在这混乱中到底发生了什么。你写的应该是在我看来,这不是一个解决方案,而是一个提示。经验教训。在这种情况下,在我看来似乎非常主观,但最终这不是我的决定。只是试图帮助OP,并不意味着冒犯。
while(toupper(choice) == 'C')
{
    cout << "Enter a row. Ex: 1,2,3... ";cin >> y;
    cout << "Enter a Letter for a seat: "; cin >> x;

    if(toupper(x) == 'A')
        x = 0;
    if(toupper(x) == 'B')
        x = 1;
    if(toupper(x) == 'C')
        x = 2;
    if(toupper(x) == 'D')
        x = 3;
    if(toupper(x) == 'E')
        x = 4;
    if(toupper(x) == 'F')
        x = 5;

    seating[y][x] = taken;
    for(int row = 1; row <= rowsz; row++)
    {
        for(int col = 0; col < colsz; col++)
        {
            cout << seating[row][col];
        }
        cout << endl;
    }
    cout << "Seat again? Press C to continue to seat and press Q to quit. "; cin >> choice;