The only problem I am running into when I run this program is that fact that my 2nd for loop doesn't print out 1,2,3 just 0,1,2. I understand why it prints out the second type but how do I fix it ? My first thought was to replace it with for(int i=1;i<3;++i) but that will skip my 0 position element all together or give me a run-time error
If anyone can help me solve this problem It would be very helpful.
Code:
#include <iostream>
#include<vector>
#include<string>
using namespace std;
int main()
{
string game0,game1,game2;
vector<string>myGames;
vector<string>::iterator iter;
cout<<"What is Your Favorite Game :";
cin>>game0;
cout<<"What is Your 2nd Favorite Game :";
cin>>game1;
cout<<"What is Your 3rd Favorite Game : ";
cin>>game2;
myGames.push_back(game0);
myGames.push_back(game1);
myGames.push_back(game2);
cout<<"\n\t\tTop 3 Favorite Games\n";
for( iter=myGames.begin(); iter!=myGames.end();++iter)
cout<<". "<<*iter<<endl;
int choice;
char replace;
cout<<"\nDo you want to replace a game (y/n) :";
cin>>replace;
while (replace=='y')
{
for(int i = 0; i<myGames.size();++i)
cout<<i<<". "<<myGames[i]<<endl;
cout<<"\nWhat is Your Choice :";
cin>>choice;
switch (choice)
{
case 1: myGames.erase(myGames.begin());
cout<<"\nWhat's Your New #1 Game ? ";
cin>>game0;
myGames.insert(myGames.begin(),game0);
break;
case 2: myGames.erase(myGames.begin()+1);
cout<<"\nWhat's Your New #2 Game ? ";
cin>>game1;
myGames.insert(myGames.begin()+1,game1);
break;
case 3: myGames.erase(myGames.begin()+2);
cout<<"\nWhat's Your New #3 Game ? ";
cin>>game2;
myGames.insert(myGames.begin()+2,game2);
break;
default: cout<<"Wrong Number Try Again\n";
continue;
}
cout<<"\nDo you want to replace another (y/n) :" ;
cin>>replace;
cout<<"\n";
}
cout<<"\n\t***Top 3 Favorite Games***\n";
for(int i = 0; i<myGames.size();++i)
cout<<i<<". "<<myGames[i]<<endl;
return 0;
}