crashes when trying to print vector

so the code compiles fine and runs like it should but when I select 5 in the program to print out the bill it crashes why is it doing this?

there is a few comments of things I tried that did not fix the problem

//nick bertell
//Final

#include <iostream>
#include <vector>
#include <string>
#include <windows.h>

using namespace std;

void displayTitle();
void displayMenu();
int getChoice();
void printGreetings(int c);
void bill();
void blutxt();
void goldtxt();
void redtxt();

vector<string> names;
vector<double> prices;
vector<double> orders;
//vector<double> preadd;
int choice;
float sum;
float total;



int main()
{
names.push_back("Golden Dragon Delight");
names.push_back("Dragon and Phoenix");
names.push_back("Seafood Goba");
names.push_back("Beach Comer");
prices.push_back (13.95);
prices.push_back(13.95);
prices.push_back(13.95);
prices.push_back(14.95);
orders.push_back(0);
//orders.push_back(0);
//orders.push_back(0);
//orders.push_back(0);
int choice;
do
{
system("cls");
displayTitle();
displayMenu();
cout << "Enter your choice: ";
choice = getChoice();
if (choice != (names.size() + 2))
{
printGreetings(choice);
}
if (choice == (names.size() + 1))
{
// cout << ("your bill comes out to");
bill();
// cout << ("with tax.");
// cout << ("and");
// cout << sum;
// cout << ("without tax.\n");
}


} while (choice != (names.size() + 2));
redtxt();
cout << "thank you for dining with the golden dragon, have a nice day.\n";
return 0;
}

//functions

//change colors
//blue
void blutxt()
{
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hConsole, FOREGROUND_BLUE | FOREGROUND_INTENSITY);
}
//yellow
void goldtxt()
{
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hConsole, FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY);
}
//red
void redtxt()
{
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hConsole, FOREGROUND_RED | FOREGROUND_INTENSITY);
}

//bill
void bill()
{
redtxt();
//vector<float> mult;

for (int i = 0; i < orders.size(); i++)
{
cout << " " << i + 1 << " " << orders[i];
}


/*for (int j = 0; j < mult.size(); j++)
{
//sum = mults contence added togather
}
//total = sum*tax
*/

}




//title
void displayTitle()
{
goldtxt();
cout << "\t\tGOLDEN DRAGON MENU\n";
cout << "\t\t==================\n\n";
;
}
// menu
void displayMenu()
{
blutxt();
for (int i = 0; i < names.size(); i++)
{
cout << " " << i + 1 << " " << names[i];
cout << " " << prices[i] << endl;
}
cout << endl;
redtxt();
cout << " " << names.size() + 1 << " bill\n\n";
cout << endl;
cout << " " << names.size() + 2 << " End program\n\n";
blutxt();
}
// greeting
void printGreetings(int c)
{
blutxt();
double amount;
cout << "You selected " << names[c - 1] << endl;
cout << "how meny would you like" << endl;
cin >> amount;
//new
orders.push_back(amount * prices[c - 1]);

//old
//}

//int i;
//for (i=0; i < choice; i++)
//{
// orders.size();
//}
//
// if (i = choice)

// {
//orders.erase(i);

// orders.push_back(prices[i] * amount);
// }


system("pause");
}

//choice
int getChoice()
{
blutxt();
int choice;
cin >> choice;
while (choice < 1 || choice > names.size() + 1)
{
cout << "Invalid input. Enter again: ";
cin >> choice;
cin.clear();
cin.ignore(100, '\n');
}
return choice;
}
//additem
//removeitem
yes because I did not know if it was considered as beginner code or not.
yes because I did not know if it was considered as beginner code or not.
Line 54: You call printGeetings with 5.

Line 148: You try to reference lines[4] which is an out of bounds reference. You pushed 4 values onto the names vector. Those elements are names[0] through names[3].

PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.
Topic archived. No new replies allowed.