What i need is to check if a string that the user inputs exists in the vector then save the location to be used to refer to a different vector.
If any one has any ideas that would be great.
int playerStats(vector<int>&PLAYER_STATS,vector<string>stats){
if (PLAYER_STATS[0]>=100){
cout<<"\nCongratulations you have levelled up!\n You have 7 points to spend, so choose wisely.";
vector<int>::const_iterator inIter;
vector<string>::const_iterator stIter;
stIter=stats.begin();
for(inIter=PLAYER_STATS.begin();inIter!=PLAYER_STATS.end();++inIter){
cout<<*stIter++<<"\t";
cout<<*inIter;
}
cout<<"Enter any of the stats above to add one point.";
for(int point=1;point!=8;++point){
cout<<"What would you like to add point number "<<point<<" to? ";
string add;
cin>>add;
for (int i=0;i<add.length();i++)
add[i]=tolower(add[i]);
while(){/*check word against vector "stats" if it isn't there do this:*/
cout<<"You have entered a invalid command. Please re-enter: ";
cin>>add;
}
//get position of "add" in vector "stats"
//add 1 to same location in "PLAYER_STATS"
}}
If this has already been asked (or something similar) a link will do just fine.
I know i have marked this as answered but I had it working fine, but i must have changed something cause it is going strait the the else clause even if the input is valid and I can't figure out why. Here is the code:
int playerStats(vector<int>&PLAYER_STATS,vector<string>stats){
if (PLAYER_STATS[0]>=100){
PLAYER_STATS[0]-=100;
cout<<"\nCongratulations you have levelled up!\n You have 7 points to spend, so choose wisely.\n\n";
vector<int>::iterator inIter;
vector<string>::const_iterator stIter;
stIter=stats.begin();
for(inIter=PLAYER_STATS.begin();inIter!=PLAYER_STATS.end();++inIter){
cout<<*stIter++<<"\t";
cout<<*inIter<<endl;
}
cout<<"Enter any of the stats above to add one point.\n";
for(int point=1;point!=8;++point)
{
cout<<"What would you like to add point number "<<point<<" to? ";
string add;
cin>>add;
for (int i=0;i<add.length();i++)
add[i]=tolower(add[i]);
bool invalid=true;
while(invalid)
{
auto match = find(begin(stats)+2,end(stats),add);
if ( end(stats) != match )
{
auto index = distance( begin(stats), match );
cout<<index;
invalid=false;
PLAYER_STATS[index]++;
}
else
{
cout<<"You have entered a invalid command. Please re-enter: ";
cin>>add;
invalid=true;
}
}
}
}
I believe line 24 is returning as false so it goes to else.
"I must have changed something"
Start reading about version control systems. Git is nice.
You do lowercase only the first attempt.
You have two vectors that should be of same size. Consider using only one vector that contains std::pair<string,int> objects, or replace vector with std::map<string,int>. Map has find().