复杂的C++作业
Complicated C++ homework
所以我正在处理剧院座位问题。程序的输出没有按应有的方式排列。我需要帮助把#和*排成合适的列。同样,按Q退出也不起作用。此外,我需要弄清楚如何从文件中读取座位表信息。如果包含座位信息的文件还不存在,则表示所有座位都是空的每当节目结束时,座位表信息都应存储在此文件中。任何其他提示也会有所帮助。这是我到目前为止的代码:
#include "stdafx.h"
# include <iostream>
# include <iomanip>
using namespace std;
void seats( double [] , int);
void mapSeats();
char movieMenu(char);
int main()
{
const int rowNum = (15.0);
double rowValue[rowNum]; //array to hold row pices
char selection;
int row2, col2;
const char TAKEN = '#';//seats taken
const char EMPTY = '*';//seats free
const int row = 15;//number of rows
const int col = 20;//number of col
char map[row][col];//array to hold seat chart
for(int i= 0;i<row;i++)//initiating array
{
for (int j=0;j<col;j++)
{
map[i][j]=EMPTY;
}
}
mapSeats();
seats(rowValue, rowNum);//ask user to enter price of each row
cout << endl;
do
{
cout << "MOVIE THEATER MENU" << endl;
cout << "------------------" << endl;
cout << "1) Sell a ticket" << endl;
cout << "Q) Quit program" << endl;
cout << "Please make a selection: ";
cin >> selection;
if(selection =='1')
{
cout << "Please enter a row number and a seat number for the ticket: " ;
cout << "Row # :" ;
cin >> row2;
cout << endl;
cout << "Seat # :" ;
cin >> col2;
cout << endl;
// Check if seat is free
if(map[row2][col2] == TAKEN) {
cout << "This seat is taken! Try another one. n";
continue; // start the loop again
}
else // and if it is - sell the ticket
map[row2][col2]=TAKEN;
// Add the next loop to immediately see the effects:
for (int i = 0; i < row; i++){
for(int j = 0; j < col; j++){
cout << map[i][j];
}
cout << endl;
}
}
else if(selection =='q'||selection=='Q')
{
cout << "Thank you for using the program." << endl;
}
else if(selection != '1' || selection !='q' || selection !='Q')
{
cout << "Invalid selection." << endl;
}
}while(selection != '1' || selection !='q' || selection !='Q');
system("pause");
return 0;
}
void seats(double rowPrice[], int row)
{
cout << "Please enter a ticket price for each row." << endl;
for(int i = 0 ; i < row; i++)
{
cout << "Row # " << i+1 << ": " ;
cin >> rowPrice[i];
}
}
void mapSeats()
{
const char TAKEN = '#';//seats taken
const char EMPTY = '*';//seats free
const int rw=20;
const int cl=15;
cout << "Seats " ;
for(int k = 0 ; k <20;k++) //loop to display nums 0 to 19
{
cout << fixed<< setw(2) << " " << k ;
}
for(int i=0;i<rw;i++)//making array display what's in it
{
cout << endl<< "Row " << i;
for(int j=0;j<cl;j++)
{
cout << fixed<< setw(2) << "" << EMPTY;
}
}
cout << endl;
}
Q退出不起作用。你的逻辑是错误的
do
{
...
} while (selection !='q' && selection !='Q');
选择不是'q'时继续,选择不是'q'时继续。对于新手来说,混淆"或"answers"和"是很常见的。
相关文章:
- 将执行、作业和WinAPI相乘
- 为什么我的多线程作业队列崩溃
- 正在解码MSVC 32位版本的程序集(作业).没有手术做什么
- 使用"Task"函数指针队列定义作业管理器
- C++秘密消息学校作业
- 动态类的分段错误(家庭作业问题)
- 我已经阅读了很多关于 2d 数组的信息,但我在作业中使用它时遇到了麻烦
- CMAKE:动态作业池更改
- C++17 排序:作业左侧的后递增
- 所以我正在为我的学校作业练习继承,但我无法正确实施标题保护
- 类作业中的非左值
- 不知道如何在家庭作业任务中实现一件事
- 我正在尝试为家庭作业加密邮件
- 将作业传递给另一个函数,而不会延迟 arduino
- 正在取消线程池中运行的任意作业
- 由 JOB 中的进程启动的子进程是否可以将 JOB 属性设置为脱离作业?
- 我正在尝试解决英特尔架构并行基础课程中关于 Coursera 的一项作业
- 复印作业操作员说明
- 是回文作业练习
- 为什么作业提交网站的输出与Visual Studio不同