간단한 질문처럼 보일 수도 있습니다. 내 콘솔을 신속하게 열고 닫을 수있는 것이 무엇인지 알 수 없습니까? 내 main() 함수에 시스템 ("PAUSE")을 포함 시켰습니다.C++ 콘솔 문제
프로그램 정보 : 이 프로그램은 다차원 배열에서 볼 수있는 것처럼 어떤 행의 좌석이 사용 가능한지를 보여주는 시네마 극장 티켓 시스템 용 프로그램입니다.
콘솔이 열리지 않는 이유를 아는 사람이 있습니까? 컴파일러에 오류 메시지가 표시되지 않습니다. 때문에 귀하의 ReadPrices에
#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;
}
명령 줄에서 프로그램을 실행 해보십시오. – Pubby
프로그램을 어떻게 운영하고 있습니까? 나는 이것이 당신의 프로그램 자체만큼이나 프로그래밍 환경에 많은 이슈가 될 것이라고 생각한다. –
@ Code-Guru - VC++ 2010 컴파일 – n0de