Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/148.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C++;按enter键继续_C++_C++11 - Fatal编程技术网

C++ C++;按enter键继续

C++ C++;按enter键继续,c++,c++11,C++,C++11,晚上,我正在寻找一种方法让程序继续,而不是在要求按enter键继续后退出。我不能使用list命令,因为我在另一个函数中调用函数“seatingChart”,并使用list命令将我返回菜单。有什么建议吗 void seatingChart() { for(row = 0; SEATROWS > row; ++row) // Placeholder for '#' for (seat = 0; SEATS > seat; ++seat) // Placeholder fo

晚上,我正在寻找一种方法让程序继续,而不是在要求按enter键继续后退出。我不能使用list命令,因为我在另一个函数中调用函数“seatingChart”,并使用list命令将我返回菜单。有什么建议吗

void seatingChart()
{
    for(row = 0; SEATROWS > row; ++row) // Placeholder for '#'
    for (seat = 0; SEATS > seat; ++seat) // Placeholder for '#'
    theater[row][seat] = '#'; // Applying '#' to the chart

    cout << "\n\t\tSeats";
    cout << "\n        123456789012345678901234567890" << endl; //seat header
    for (int row = 0; SEATROWS > row; ++row) 
    { // Initializing 15 rows
        cout << "\nRow " << setw(2) << row+1 << "\t";
        for (int seat = 0; SEATS > seat; ++seat)
        { // Initializing 30 seats
            cout << theater [row][seat];} //display seating chart
        }

        cout << "\n\n\n\tLegend:\t*  =  Sold";
        cout << "\n\t\t#  =  Available";

        cout << "\n\n\nPress the Enter key to continue.";
        cin.ignore();
        cin.get();
    }
}
void seatingChart()
{
for(row=0;SEATROWS>row;++row)//用于“#”的占位符
for(seat=0;SEATS>seat;++seat)//用于“#”的占位符
剧院[排][座位]='#'//将'#'应用于图表

cout除非您将整个菜单代码包装在一个循环中,并将此循环的退出条件设置为用户输入(在您的情况下键入5退出),否则程序将在从seatingchart()函数返回时立即终止,因为list()函数将返回main(即seatingchart()返回到list()而list()将返回到main())。您应该执行以下操作:

do
{
   cout << "\n\n\n\t\tC++ Theatre" << endl << endl;
   cout << "\n\t1.  View Available Seats";
   cout << "\n\t2.  View Seating Prices";
   cout << "\n\t3.  View Ticket Sales";
   cout << "\n\t4.  Purchase a Ticket";
   cout << "\n\t5.  Exit the Program\n\n";
   cout << "\n\tEnter your choice(1-5):  ";
   cin>>choice;

   while(choice>5 || choice<1)
   {
      cout<<"Choice must be between 1 and 5. Please re-enter:";
      cin>>choice;
   }

   if (choice == 1)
      seatingChart();
   else if (choice == 2)
      getPrices();
   else if (choice == 3)
      viewSales();
   else if (choice == 4)
       ticketSales();
   else if (choice==5)//this is your exit condition
        break;//will break out of the menu loop
}while(1);//the is your menu loop
do
{

您为什么要调用
cin.ignore()
cin.get()
?无论如何,导致程序退出的原因必须在调用
seatingChart()的函数中
-我们无法修复您未发布的代码中的错误。这就是为什么网站策略要求您提供一个最小的、完整的、可验证的示例,我们可以运行它来重现问题……请参阅。感谢您的回复,我是这个网站上的一个noob。让我上传整个代码。
我无法使用list命令,因为我正在调用函数另一个函数中的“seatingChart”并使用list命令将我送回菜单。
这意味着什么?A将大大改善问题。我肯定
剧院[row][seat]==take;
不会做你认为它会做的事(这是条件等价性检查;不是作业)此外,
totalPrice+=price[row][COLS];
显然是错误的,因为
price
首先只
COLS
宽,因此从0..COLS-1开始不灵活。这在多个地方重复,包括
cin>>price[x][COLS]
do
{
   cout << "\n\n\n\t\tC++ Theatre" << endl << endl;
   cout << "\n\t1.  View Available Seats";
   cout << "\n\t2.  View Seating Prices";
   cout << "\n\t3.  View Ticket Sales";
   cout << "\n\t4.  Purchase a Ticket";
   cout << "\n\t5.  Exit the Program\n\n";
   cout << "\n\tEnter your choice(1-5):  ";
   cin>>choice;

   while(choice>5 || choice<1)
   {
      cout<<"Choice must be between 1 and 5. Please re-enter:";
      cin>>choice;
   }

   if (choice == 1)
      seatingChart();
   else if (choice == 2)
      getPrices();
   else if (choice == 3)
      viewSales();
   else if (choice == 4)
       ticketSales();
   else if (choice==5)//this is your exit condition
        break;//will break out of the menu loop
}while(1);//the is your menu loop