For school, for a project I worked in three separate files for creating it and when I got everything together the program runs but crashes at a certain point. Could someone please try and help I asked the teacher and he didn't know. Here is the code. Thanks!
#include <iostream>
#include <string>
#include <cmath>
#include <fstream>
using namespace std;
void Show_Chart ();
const char FULL = '*';
const char EMPTY = '#';
const int rows = 15;
const int columns = 30;
char map [rows][columns];
double price;
int cost;
int total = 5;
int seat = 450;
int seat2 = 0;
int Quit = 1;
int main()
{
const int Num_Rows = 15;
int price [Num_Rows];
int row2, column2, cost;
int answer;
int selection;
int ticcost;
int ticcost2;
int moviesel;
char member;
string username;
string password;
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < columns; j++)
map [i][j] = EMPTY;
}
cout << "Welcome to Emagination Station Movie Theater Please login below to buy tickets. \n\n";
cout << "\Are you a Member?\n\n";
cout << "\Y or N\n\n";
cin >> member;
if(member == 'Y')
{cout << "Username: ";
cin >> username;
cout << "Password: ";
cin >> password;
if (username == "Colin" && password == "4901")
{cout << "\nSuccessful Login, Welcome Colin\n\n";}
else if (username == "Obsniuk" && password == "1234")
{cout << "\nSuccessful Login, Welcome Mr.Obsniuk\n\n";}
else if (username == "Grant" && password == "1273")
{cout << "\nSuccessful Login, Welcome Grant\n\n";}
else if (username == "Michael" && password == "5463")
{cout << "\nSuccessful Login, Welcome Michael\n\n";}
else {cout << "Incorrect username/password" << endl;
cout << "Please try again" << endl;}
}
if(member == 'N')
{
cout << "\nWhat movie would you like to see?\n\n";
cout << "\nTrolls\n\n";
cout << "\nThe Edge of Seventeen\n\n";
cout << "\nOffice Christmas Party\n\n";
cout << "\nNocturnal Animals\n\n";
cout << "\nMoana\n\n";
cout << "\nMiss Sloane\n\n";
cout << "\nIncarnate\n\n";
cout << "\nHacksaw Ridge\n\n";
cout << "\nFantastic Beasts and Where to Find Them\n\n";
cout << "\nDoctor Strange\n\n";
cout << "\nBleed for This\n\n";
cout << "\nBad Santa 2\n\n";
cout << "\nArrival\n\n";
cout << "\nAlmost Christmas\n\n";
cout << "\nAllied\n\n";
cout << "\nRogue One: A Star Wars Story\n\n";
cout << "\nEnter Movie\n\n";
cin >> moviesel;
cout << "Type in 1 to view available seats." << endl;
cout << "Type in 2 to purchase ticket." << endl;
cin >> selection;
{
cout << "View Available Seats\n\n";
Show_Chart();
}
// if (selection == 2)
{
cout << "Purchase a Ticket\n\n";
do
{
cout << "Please select the row you would like to sit in: ";
cin >> row2;
cout << "Please select the seat you would like to sit in: ";
cin >> column2;
if (map [row2] [column2] == '*')
{
cout << "Sorry that seat is sold-out, Please select a new seat.";
cout << endl;
}
else
{
cout << "That ticket costs: $" << cost << " dollars" << endl;
cout << "Confirm Purchase? Enter (1 = YES / 2 = NO)";
cin >> answer;
seat = seat - answer;
seat2 += answer;
if (answer == 1)
{
cout << "Your ticket purchase has been confirmed." << endl;
map [row2][column2] = FULL;
}
else if (answer == 2)
{
cout << "Would you like to look at another seat? (1 = YES / 2 = NO)";
cout << endl;
cin >> Quit;
cost = cost + 5;
}
cout << "Would you like to look at another seat?(1 = YES / 2 = NO)";
cin >> Quit;
cost = cost + 5;
}
}
while (Quit == 1);
}
{
cout << "View Available Seats\n\n";
Show_Chart ();
}
cout << "How many Buckets of popcorn would you like? $5 a Bucket. (Standerd 2oz Bucket) " << endl;
int pop;
cin >> pop;
cout << "How many bottles of Mountain Dew would you like? $1.99 Each." << endl;
int dew;
cin >> dew;
cout << "How many bottles of Diet Pepsi would you like? $1.99 Each." << endl;
int diet;
cin >> diet;
cout << "How many bottles of Gatorade would you like? $1.99 Each." << endl;
int gatorade;
cin >> gatorade;
cout << "How many cans of IZZE would you like? $1.99 Each." << endl;
int izze;
cin >> izze;
cout << "How many bottles of Aqufina would you like? $1.99 Each." << endl;
int water;
cin >> water;
cout << "How many bottles of Brisk Iced Tea would you like? $1.99 Each." << endl;
int tea;
cin >> tea;
if (username == "Colin" && password == "4901" || username == "Obsniuk" && password == "1234" || username == "Grant" && password == "1273" || username == "Michael" && password == "5463")
{
cout << "\nThank You for being a proud member. What movie would you like to see?\n\n";
cout << "\nTrolls\n\n";
cout << "\nThe Edge of Seventeen\n\n";
cout << "\nOffice Christmas Party\n\n";
cout << "\nNocturnal Animals\n\n";
cout << "\nMoana\n\n";
cout << "\nMiss Sloane\n\n";
cout << "\nIncarnate\n\n";
cout << "\nHacksaw Ridge\n\n";
cout << "\nFantastic Beasts and Where to Find Them\n\n";
cout << "\nDoctor Strange\n\n";
cout << "\nBleed for This\n\n";
cout << "\nBad Santa 2\n\n";
cout << "\nArrival\n\n";
cout << "\nAlmost Christmas\n\n";
cout << "\nAllied\n\n";
cout << "\nRogue One: A Star Wars Story\n\n";
cout << "\nEnter Movie\n\n";
cin >> moviesel;
cout << "Type in 1 to view available seats." << endl;
cout << "Type in 2 to purchase ticket." << endl;
cin >> selection;
{
cout << "View Available Seats\n\n";
Show_Chart ();
}
// if (selection == 2)
{
cout << "Purchase a Ticket\n\n";
do
{
cout << "Please select the row you would like to sit in: ";
cin >> row2;
cout << "Please select the seat you would like to sit in: ";
cin >> column2;
if (map [row2] [column2] == '*')
{
cout << "Sorry that seat is sold-out, Please select a new seat.";
cout << endl;
}
else
{
cout << "That ticket costs: $" << cost << " dollars" << endl;
cout << "Confirm Purchase? Enter (1 = YES / 2 = NO)";
cin >> answer;
seat = seat - answer;
seat2 += answer;
if (answer == 1)
{
cout << "Your ticket purchase has been confirmed." << endl;
map [row2][column2] = FULL;
}
else if (answer == 2)
{
cout << "Would you like to look at another seat? (1 = YES / 2 = NO)";
cout << endl;
cin >> Quit;
cost = cost + 5;
}
cout << "Would you like to look at another seat?(1 = YES / 2 = NO)";
cin >> Quit;
cost = cost + 5;
}
}
while (Quit == 1);
}
{
cout << "View Available Seats\n\n";
Show_Chart ();
}
cout << "How many Buckets of popcorn would you like? $5 a Bucket. (Standerd 2oz Bucket) " << endl;
int pop;
cin >> pop;
cout << "How many bottles of Mountain Dew would you like? $1.99 Each." << endl;
int dew;
cin >> dew;
cout << "How many bottles of Diet Pepsi would you like? $1.99 Each." << endl;
int diet;
cin >> diet;
cout << "How many bottles of Gatorade would you like? $1.99 Each." << endl;
int gatorade;
cin >> gatorade;
cout << "How many cans of IZZE would you like? $1.99 Each." << endl;
int izze;
cin >> izze;
cout << "How many bottles of Aqufina would you like? $1.99 Each." << endl;
int water;
cin >> water;
cout << "How many bottles of Brisk Iced Tea would you like? $1.99 Each." << endl;
int tea;
cin >> tea;
I think your issue is when the program request that you enter a movie selection you are supposed to supply an integer value as opposed to the movie name due to variable moviesel being of type int. The problem a user will have is that you do not place ordering numbers next to each movie so your users will intuitively enter the ,movie name. Depending on the name entered your input stream cin might overflow thus loading the subsequent input required for row and column to values that fall out of the range of the array which will cause a crash.
To rectify you should place ordering values next to your movies and read in strings instead of values which you can then check for correctness and convert to the associated value. You should also check the values entered to ensure that it does not fall outside of the valid range.