I am trying to create a program that will allow you to add up amounts of troops that different people own. To do this, I'm using deques. I keep getting a weird problem while my program is running. It says, "The application has requested the runtime to terminate in an unusual way. Please contact support team blah blah blah."
deque<string> names;
string nameInput;
int typeNum;
int nameCounter = 0;
int typeCounter = 0;
int monsterCounter = 0;
int numberCounter = 0;
deque<string> monsters;
string monsterInput;
deque<int> troopNum;
int numberInput;
cout << "Please type the name of who owns the troops: ";
getline(cin,nameInput);
names.push_back(nameInput);
nameCounter++;
cout << "How many types of troops are to be entered for this user: ";
cin >> typeNum;
typeCounter++;
while(typeCounter < typeNum)
{
cout << "Please type the name of the troop or monster: "; // IT CRASHES RIGHT HERE!!!!
getline(cin,monsterInput);
monsters.push_back(monsterInput);
monsterCounter++;
cout << "Please type the number of " << monsters.at(monsterCounter) << " that " << names.at(nameCounter) << " owns: ";
cin >> numberInput;
cin.ignore();
}
I suppose the error is on line 30. When there is one element in deque, monsterCounter = 1, but to access the element you'd write monsters.at(0) ( or monsters[0] ). Deques, just like arrays, start from 0. Try monsterCounter-1 and nameCounter-1.