Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/154.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++;控制台问题_C++_Arrays_Function_Multidimensional Array - Fatal编程技术网

C++ C++;控制台问题

C++ C++;控制台问题,c++,arrays,function,multidimensional-array,C++,Arrays,Function,Multidimensional Array,这似乎是一个简单的问题,但我不知道是什么让我的控制台快速打开和关闭?我在main()函数中包含了系统(“暂停”) 节目信息: 该程序用于电影院票务系统,显示哪一排的座位可用(如多维数组所示) 有人知道为什么控制台不能打开吗?我在编译器中没有收到任何错误消息 #include <iostream> #include <fstream> using namespace std; using std::ifstream; void Init(); void Display()

这似乎是一个简单的问题,但我不知道是什么让我的控制台快速打开和关闭?我在main()函数中包含了系统(“暂停”)

节目信息: 该程序用于电影院票务系统,显示哪一排的座位可用(如多维数组所示)

有人知道为什么控制台不能打开吗?我在编译器中没有收到任何错误消息

#include <iostream>
#include <fstream>
using namespace std;
using std::ifstream;

void Init();
void Display();
void SellTicket();
void ReadPrices();

 char tickets[15][20];
 int revenue = 0;
 int ticketsSold = 0;
 int prices[15];

 int main()
 {
Init();
ReadPrices();
int choice;

    cout << "Enter your choice: " << endl;
    cout << "Press 1 for Display Chart" << endl;
    cout << "Press 2 for sell ticket" << endl;
    cout << "Press 3 for exit" << endl;
    cin >> choice;
    cout << endl;
    switch(choice)
    {
    case 1:
        Display();
        break;
    case 2:
        SellTicket();
        break;
    case 3:
        exit(0);
        break;
    }

system("PAUSE");
return 0;
 }


 void Init()
 {
for (int row = 0; row < 15; row++)
{
    for (int col = 0; col < 20; col++)
    {
        tickets[row][col]='*';
    }
}
 }


 void Display()
 {
cout <<"Seats:\t0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19"<<endl;
for (int row = 0; row < 15; row++)
{
    cout << "Row"<< row << "\t";
    for (int col = 0; col < 20; col++)
    {
        if(col < 10)
            cout << tickets[row][col] << " ";
        else
            cout << tickets[row][col] << "  ";
    }
    cout << endl;
    cout << endl;
}

cout << "Total sold seats are: " << ticketsSold << endl;
cout << "Total revenue is: " << revenue << endl;
cout << endl;

 }

 void SellTicket()
 {
int rowNo,seatNo;
//while(1)
//{
    cout << "Enter Row Number:";
    cin >> rowNo;
    cout << endl;

    cout << "Enter Seat Number:";
    cin >> seatNo;
    cout << endl;

    if (tickets[rowNo][seatNo]=='#')
    {
        cout << "Ticket is not available " << endl;
        cout << endl;
        SellTicket();
    }
    else
    {
        tickets[rowNo][seatNo]='#';
        revenue+=prices[rowNo];
        ticketsSold+=1;

        char c;
        cout << "Would you like to sell another ticket? Press y for yes or      n for no: ";
        cin >> c;
        cout << endl;
        if (c=='y')
        {
            SellTicket();
        }
    }
//}
 }

 void ReadPrices()
 {
int count=0;
ifstream indata; 
int num; 
indata.open("prices.dat"); 
if(!indata) 
{ 
  cerr << "Error: file could not be opened" << endl;
  exit(1);
}
indata >> num;
while ( !indata.eof() ) 
{ 
    prices[count++]=num;
  //cout<< "The next number is " << num << endl;
  indata >> num; 
}
indata.close();
//cout << "End-of-file reached.." << endl;
 }
#包括
#包括
使用名称空间std;
使用std::ifstream;
void Init();
void Display();
作废门票();
无效读取价格();
煤票[15][20];;
国际税收=0;
int ticketssell=0;
国际价格[15];
int main()
{
Init();
阅读价格();
智力选择;
cout因为在ReadPrices()函数中,无法打开prices.dat文件,只需退出(1)应用程序

  indata.open("prices.dat"); 
  if(!indata) 
  { 
    cerr << "Error: file could not be opened" << endl;
    exit(1);
  }
indata.open(“prices.dat”);
如果(!indata)
{ 
cerr我相信exit()是由ReadPrices调用的。
exit()不调用系统(“暂停”)

可能的解决办法:

  • std::at_exit()
  • 如果ReadPrices函数成功,则使其返回布尔值to标志,而不是调用exit

尝试从命令行运行您的程序。您的程序是如何运行的?我怀疑这与您的程序本身一样是编程环境的问题。@Code Guru-VC++2010