So, I'm doing a RPG text based game and I need somewhere in the game for the person to choose their gender and role:
- I have a variable called
int userInput
that is used to store the user's choice based on the number written like:
1. Go west
2. Go east
- I have an aray called
int playerInfo[2]
, what it does is that i ask the user whats his gender (1. Boy 2. Girl) and it is stored in
playerInfo[0]
like
1 2
|
cin >> userInput;
playerInfo[0]=userInput;
|
and the role (1. Warrior 2. Archer) is stored in
playerInfo[1]
the same way.
My problem
I need to, after the user submits their gender and role and they are stored in the array, have an ouput like:
"So, you're a *gender* and *role* is that correct?"
I've put two int variables called genderNr and roleNr to store the userInput to help me like this:
1 2 3 4
|
cout << " For starters, are you a boy or a girl?\n 1:Boy\n 2: Girl\n";
cin>>userInput;
playerInfo[0]= userInput; //Stores the character's gender
genderNr=userInput;
|
And then I wanna run it through a function that says that if genderNr == 1 then
string gender='boy'. So far this is what I've done to try to make it work:
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
|
#include <iostream>
#include <string>
(...)
//the rest of the variables don't matter
int genderNr = 0;
int roleNr = 0;
string gender;
string genderFunc;
//Just so you can see i've declared everything
(...)
cout << "So you say you are a " << genderFunc(genderNr) ;
(...)
string genderFunc(int genderNr) {
if (genderNr == 1) {
string gender='boy';
}
return gender;
}
|
Then I get errors like:
In function `void newGameFunc()':
no match for call to `(std::string) (int&)'
In function `std::string genderFunc(int)':
`std::string genderFunc(int)' redeclared as different kind of symbol
previous declaration of `std::string genderFunc'
previous non-function declaration `std::string genderFunc'
conflicts with function declaration `std::string genderFunc(int)'
[Warning] multi-character character constant
invalid conversion from `int' to `const char*'
initializing argument 1 of `std::basic_string<_CharT, _Traits, _Alloc>::basic_string(const _CharT*, const _Alloc&) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]'
What's wrong?? Please help me as soon as possible and thank you very much for your help.