MD 阵列未更新
MD array not updating
我正在尝试完成编程入门的家庭作业项目。我们刚刚讨论了多维数组。
我们应该设计一个程序,该程序必不可少地充当飞机上预订座位的系统。您选择一个座位,如果可用,则用"X"字符标记,表示它已被选中。如果您选择的座位不可用(标有"X"),则系统会告诉您该座位不可用,并可以选择再次选择。每次选择后,飞机的座位图都会更新。
我一直遇到的问题是地图没有正确更新。在向我的教授寻求帮助后,她建议我改变循环,但我不确定我将如何改变它。有人可以给我一些帮助吗?(以下信息): 座位图如下所示:
- 阿 乙 中 德
- 阿 乙 中 德
- 阿 乙 中 德
- 阿 乙 中 德
- 阿 乙 中 德
- 阿 乙 中 德
-
阿 乙 中 德
int row, col; char seats[7][5], choice; ifstream input; input.open("plane.txt"); for(int a = 0; a<7; a++) { cout<<"n"; for(int b = 0; b<5; b++) { input>>seats[a][b]; cout<<seats[a][b]<<" "; } } do { cout<<"What row would you like to sit in?n"; cin>>row; cout<<"What seat would you like? (A=1, B=2, C=3, D=5)"; cin>>col; if(seats[row][col]=='X') cout<<"Sorry this seat is already taken. Try another.n"; else { cout<<"Your seat has been reserved."; cout<<" Be sure to check the updated seat chart to confirm your order."; seats[row][col]='X'; } for(int c = 0; c<7; c++) { cout<<"n"; for(int d = 0; d<5; d++) { cout<<seats[c][d]<<" "; } } cout<<"n"; cout<<" Would you like to pick another seat? (Y/N)"; cin>>choice; } while((choice=='y')||(choice=='Y')); return 0;
}
你需要处理数组索引。
if(seats[row-1][col-1]=='X')
cout<<"Sorry this seat is already taken. Try another.n";
else {
cout<<"Your seat has been reserved.";
cout<<" Be sure to check the updated seat chart to confirm your order.";
seats[row-1][col-1]='X';
}
相关文章:
- 从C++本机插件更新Vector3数组
- QGraphicsPolygonItem在拖动时未更新QPolygonF坐标
- OpenMP阵列性能较差
- 如何将三维尺寸不固定的三维阵列展平为一维阵列
- 当我的阵列太大时出现分段错误
- cmake更新缓存的变量
- 更新到莫哈韦后出现cmath错误
- OpenMP:并行更新数组总是需要减少数组吗
- 位阵列上的快速AND运算
- 为什么我的变量没有更新,我的 LED 没有亮起?
- 指针没有更新它在void函数内部指向的值
- 如何在c++中获取要更新的值
- 已修改的LinkedList未在文本文件本身中更新
- Qt:当QListView获得新条目时,如何更新QStringList
- MD 阵列未更新
- 传递和更新结构阵列
- 为什么我的阵列没有更新
- boost::进程间更新阵列的最快方法
- OpenGL更新顶点阵列/缓冲区
- 使用OpenMP原子并行更新矩阵列