如何标记电影院的座位。C程序设计
首先,我想说我是C和编程的初学者。 C是我的第一语言,我觉得它很有趣。 我正在写一个模拟电影软件的程序。我的意思是你选择电影,时间和座位。 我已经完成了电影和时间的选择,但是我的座位有问题。 我想做的事情是,当你选择行和列时,在控制台中打印出坐在哪个座位上,改变颜色,增加字体等等 这是我的密码:如何标记电影院的座位。C程序设计,c,console,C,Console,首先,我想说我是C和编程的初学者。 C是我的第一语言,我觉得它很有趣。 我正在写一个模拟电影软件的程序。我的意思是你选择电影,时间和座位。 我已经完成了电影和时间的选择,但是我的座位有问题。 我想做的事情是,当你选择行和列时,在控制台中打印出坐在哪个座位上,改变颜色,增加字体等等 这是我的密码: void SeatSelection() { int row = 0; int column = 0; int i, j; printf("\t\t\t\tSCREEN
void SeatSelection()
{
int row = 0;
int column = 0;
int i, j;
printf("\t\t\t\tSCREEN\n\n\n\n\n\n\n");
int A[11][11] = {
{ 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 },
{ 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 },
{ 3, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 },
{ 4, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 },
{ 5, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 },
{ 6, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 },
{ 7, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 },
{ 8, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 },
{ 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 },
{ 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }
};
for (i = 0; i < 10; i++)
{
for (j = 0; j < 11; j++)
printf("%d\t", A[i][j]);
printf("\n\n");
}
do
{
printf("Choose seat: Row and Column\n");
scanf("%d %d", &row, &column);
if ((row<1 || row>10) && (column<1 || column>10)) printf("Wrong choice, try again\n");
} while ((row<1 || row>10) && (column<1 || column>10));
}
提前感谢您的帮助:尝试使用第二张桌子[]。对于一个座位行,如果该座位已被占用,则列take[row][column]为1,否则为0。代码:
#include <stdio.h>
void SeatSelection()
{
int row = 0;
int column = 0;
int i, j;
int A[11][11] = {
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 },
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 },
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 },
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 },
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 },
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 },
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 },
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 },
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 },
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }
};
int taken[11][11] = {
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
};
printf("============= The Cinema ==============\n");
for (i = 1; i <= 10; i++)
{
for (j = 1; j <= 10; j++)
printf(" %d ", A[i][j]);
printf("\n");
}
fflush(stdout);
do
{
printf("Choose seat: Row and Column\n");
fflush(stdout);
scanf("%d %d", &row, &column);
if ((row<1 || row>10) && (column<1 || column>10)) printf("Wrong choice, try again\n");
if(taken[row][column]) printf("This seat is taken, try again\n");
else {
taken[row][column] = 1;
printf("======== The Cinema =========\n");
for (i = 1; i <= 10; i++)
{
for (j = 1; j <= 10; j++) {
if(taken[i][j] == 0)
printf(" %d ", A[i][j]);
else
printf("[%d] ", A[i][j]);
}
printf("\n");
}
}
fflush(stdout);
} while (true);
}
int main() {
SeatSelection();
return 0;
}
编辑
我对你的代码做了一些修改,但我想你明白了:如果你不懂什么,就告诉我…这正是我的想法,非常感谢!!!编辑:我不明白你为什么将第一列和第二行更改为0?@user3476022我对第一行的用法和最后一列的初始化有点困惑。从这两个方面来看,第二个更重要,因为编译器将随机整数放在未初始化的位置,这可能会导致特殊的运行时错误。。。