Hi, I've ran in to a slight hiccup with creating a console based Hangman game.
I'm basing the code off of an example I was given at college written in VisualBasic. Basically, it takes a phrase from the user and then creates a char array of either '*' or ' ' which is then displayed and updated everytime the user guesses a letter correctly (here's the source code):
Dim Position As Integer
For Position = 1 To Len(NewPhrase)
IndividualLettersArray(Position) = Mid(NewPhrase, Position, 1)
If IndividualLettersArray(Position) = " " Then
GuessStatusArray(Position) = " "
Else
GuessStatusArray(Position) = "*"
End If
Next
Now when I try and do the same thing in C++:
Length = Phrase.length();
while (Position <= Length)
{
if (Phrase.at(Position) == " ")
{
GuessArray[Position] = " ";
}
else
{
GuessArray[Position] = "*";
}
Position = Position++;
}
I get an error: error: ISO C++ forbids comparison between pointer and integer.
I'm writing the code as plain text, saving as .cpp and the compiling the code with g++ in Terminal if that helps.
I've searched various way's of getting a character from string and always the same error.
Any help would be greatly appreciated!
I'm basing the code off of an example I was given at college written in VisualBasic. Basically, it takes a phrase from the user and then creates a char array of either '*' or ' ' which is then displayed and updated everytime the user guesses a letter correctly (here's the source code):
Dim Position As Integer
For Position = 1 To Len(NewPhrase)
IndividualLettersArray(Position) = Mid(NewPhrase, Position, 1)
If IndividualLettersArray(Position) = " " Then
GuessStatusArray(Position) = " "
Else
GuessStatusArray(Position) = "*"
End If
Next
Now when I try and do the same thing in C++:
Length = Phrase.length();
while (Position <= Length)
{
if (Phrase.at(Position) == " ")
{
GuessArray[Position] = " ";
}
else
{
GuessArray[Position] = "*";
}
Position = Position++;
}
I get an error: error: ISO C++ forbids comparison between pointer and integer.
I'm writing the code as plain text, saving as .cpp and the compiling the code with g++ in Terminal if that helps.
I've searched various way's of getting a character from string and always the same error.
Any help would be greatly appreciated!