How do I make this into a function? I've been trying to figure it out over the last 5 hours and have not gotten anywhere...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
vector<string> games;
string faves;
string game;
cout << "How Many Favorite Games Do You Have?\n";
cin >> faves;
int i = atoi(faves.c_str());
while(i>0)
{
cout << "\nPlease Enter game names " << i << " :";
cin >> game;
games.push_back(game);
i--;
}
cout << "Your Favorite Games Are: " << endl;
int g = 0;
while(games.size() > g)
{
cout <<g+1<<" "<< games[g]<< endl;
g++;
}
cout << endl;
}
|
Last edited on
What part of the program are you trying to automate with a function? How do you intend to use the function?
Last edited on
i am trying to make a function, to do the exact same thing this program is doing.
Well I don't see any parameters so it could probably look like this:
1 2 3 4 5 6 7 8 9 10 11 12
|
void yourfunc();
int main()
{
yourfunc();
return 0;
}
void yourfunc()
{
// your prog here
}
|
Were you getting any errors? If so what were you getting?
Last edited on
i dont really know how to do a function at all...My program works perfectly with the vectors. I just don't know how to change it to functions now...
Yeah I'm still kinda confused...sorry.
I found out I need to do a function for Input and a function for Output.