Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8858749
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:53:55+00:00 2026-06-14T14:53:55+00:00

This may seem like a simple question, bu tI just can’t figure out what

  • 0

This may seem like a simple question, bu tI just can’t figure out what it is that makes my console rapidly open and close? I included system(“PAUSE”) in my main() function.

Program informaton:
This program is for a cinema theater ticket system that shows which seats in which row are available (as you can see for the multidimensional arrays).

Anybody know why the console won’t stay open? I’m not getting ANY error messages in the compiler.

#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;
 }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T14:53:57+00:00Added an answer on June 14, 2026 at 2:53 pm

    Because in your ReadPrices() function, you fail to open prices.dat file and simply exit(1) application

      indata.open("prices.dat"); 
      if(!indata) 
      { 
        cerr << "Error: file could not be opened" << endl;
        exit(1);
      }
    

    If you are using VisualStudio, run application, CTL + F5 the console will stay.

    Learn how to debug your application is very important, step through each line of code and you can find the issue easily for your case.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This may seem like a silly question but I can't figure it out. let's
This may sound like a simple question, but I just cannot seem to find
This may seem like a simple question, but I can't find the answer anywhere
This may seem like a simple question but i am getting an error when
this may seem like a very simple question, but I want to dump some
This seems to me like a very simple question, but I can't seem to
This may seem like a very simple question, however I haven't been able to
This seems like a simple question but I can't seem to find an answer
Sorry if this question may be simple, but I can't seem to find an
This may seem like a simple and straightforward question and it probably has a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.