团体项目剧院座位切换声明
Group Project Theater seating switch statement
试图使主要内容尽可能简单,但无法使其工作。在代码中,main中有一个switch语句,但我需要将switch语句中的每个情况放入单独的函数中。请帮忙!
选项 = 菜单();
switch(choice)
{
case 1:
cout <<"Seating Pricesnn";
for(int count=0;count<ROWS; count++)
{
cout <<"The price for row " << (count+1) <<": $";
cout <<price[count] <<endl;
getch();
}
break;
case 2:
cout <<"Purchase Ticketsnn";
do
{
cout <<"Please enter the row: ";
cin >>rowChoice;
cout <<"Please enter the seat: ";
cin >>seatChoice;
if(seating[rowChoice][seatChoice] == '*')
{
cout <<"That seat is unavailable please make another selection.n";
}
else
{
cost = price[rowChoice] + 0;
total += cost;
cout <<"Ticket price: " <<cost <<endl;
cout <<"Please confirm your purchase. Enter 1 for yes, 2 for no.";
cin >>confirm;
if(confirm==1)
{
cout <<"Your ticket purchase has been confirmed.n";
seating[rowChoice][seatChoice] = TAKEN;
ticketSales++;
}
else if (confirm==2)
{
cout <<"Would you like to purchase another ticket? Enter 1 for yes, 2 for no." <<endl;
cin >>quit;
}
cout <<"Would you like to purchase another ticket? Enter 1 for yes, 2 for no.";
cin >>quit;
}
}
while (quit==1);
break;
case 3:
int viewRow;
cout <<"View Seats by Rownn";
cout <<"Enter the row you would like to view";
cin >>viewRow;
seatingChartRow(viewRow);
cout <<"Press 1 to return to the main menu.";
cin >>quit;
break;
case 4:
cout <<"Sales Statisticsnn";
saleStats ();
break;
case 5:
cout <<"Quitn";
break;
default: cout <<"Error Inputn";
}
}
只需这样做:
choice = menu();
switch(choice)
{
case 1:
seating();
break;
case 2:
buy_tickets();
break;
case 3:
view_seats();
break;
case 4:
saleStats ();
break;
case 5:
cout <<"Quitn";
break;
default: cout <<"Error Inputn";
}
并在必要的功能中做你的 cin/cout 事情。
你甚至自己为saleStats做了这个,所以不确定是什么混乱?
相关文章:
- .cpp和.h文件中的模板专用化声明
- 使用C++库在Android项目中修改gradle中的cmake参数,用于插入指令的测试
- 无法在 CLion 中构建 C++ 项目
- 运行同一解决方案的另一个项目的项目
- C++不正确,不需要重新声明类成员变量 MFC 手工解决方案/项目 MS VS 2015
- 我们是否应该在项目中包含的所有文件中声明外部变量
- 我应该如何修复 winnt.h 中的非法声明以避免禁用项目的质量检查?
- 在同一项目 (Cork+VTK) 中使用 2 个库时C++无法识别的模板声明
- 我应该如何在我的C++项目中声明全局变量
- yyparse()未在Bison/Flex C++项目中声明,仅适用于某些版本的gcc/Bison/Flex
- 尝试在Linux Mint 17.1 64位上"make" C++项目时从cstdlib和类似内容编译错误(未声明/不是类型)
- 有没有办法在同一项目中的另一个.cpp中使用.cpp中声明的静态空隙
- 团体项目剧院座位切换声明
- LPCSTR 在 CLR 项目中创建未声明的变量
- 无法在 xcode ios 项目中声明C++向量
- 第三方库抱怨MAXPATHLEN没有在一个项目中声明,但在其他项目中没有声明
- 在不同项目(没有编译时链接)使用的标头中声明的纯抽象C++类是否共享相同的虚拟表模型
- mErrCount:虽然在项目属性的include路径中声明了标识符,但未找到该标识符
- 使用在整个项目的不同文件中声明的对象
- 如何在同一解决方案下为多个项目声明公共#define