Mar 13, 2019 at 5:31pm UTC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
std::vector <std::string> AskPlayer1(std::vector <std::string> &Vector, const char * Player1) {
std::string Answer;
while (true ) {
std::cout << "[Player] " ;
std::getline(std::cin, Answer);
for (int i = 1; i < 10; i++) {
char j = (char )i;
if (Answer[0] == j) {
Vector[i - 1] = Player1;
std::cout << "Works" ;
break ;
}
}
}
return Vector;
}
Ex. If Answer[0] is '1' and j is '1' (I've debugged and this was an outcome) the if statement still doesn't become true. ?????
Last edited on Mar 13, 2019 at 8:34pm UTC
Mar 13, 2019 at 5:48pm UTC
> char j = (char)i;
This doesn't turn 1 into '1'.
Try
char j = i + '0';
Mar 13, 2019 at 5:50pm UTC
or
for(int i = '0'; i <= '9'; i++) //or '1' .. unclear if you wanted zero?
Last edited on Mar 13, 2019 at 5:51pm UTC
Mar 13, 2019 at 6:14pm UTC
More weirdness.
1. Vector[i = 1] = Player1;
Why the assignment (which you never use), why not Vector[1] = Player1;
2. break;
This only breaks out of your for loop, you're still stuck in your while loop.
3. return Vector;
You already passed it by reference anyway, so this is just a massive duplication of the data structure for no apparent good reason.
Mar 13, 2019 at 8:31pm UTC
Yes it's an unfinished function as I couldn't proceed clearly without that little loop to work, and the Vector[I =1] was a typo should be Vector[I- 1]
Mar 14, 2019 at 12:40am UTC
you will want to watch assignment. Its one place where a lot of junk will compile and run while doing nothing like what you wanted.... like in this case. You get a warning, if you are lucky.