View Single Post
  #1 (permalink)  
Old 12-13-2007, 10:48 PM
sondratheloser sondratheloser is offline
Member
 
Join Date: Dec 2007
Location: Philly
Posts: 3
sondratheloser is on a distinguished road
Send a message via AIM to sondratheloser
Cannot convert from char to String error
Still working on my hangman program from yesterday (Thanks Shoeninja for help!)

I re-did a bunch of it to include global variables and such

here is the method I am still having problems with:
BuildWord is a global string variable with the value " " (8 spaces). the loop compares your 1-char guess with all 8 characters of a randomly chosen 8-letter word. What buildword does is keep track of the word you've guessed so far. So say the word is aardvark, and you guess "a" I want buildword set to "aa a ", using cnt from the for loop to replace the appropriate spaces.

"String tempword = BuildWord.charAt(cnt)" is where I am getting the cannot convert from char to string error.

Code:
public static void compare () {//BEGIN COMPARISON BuildWord=" "; for (int cnt=0;cnt <=7; cnt++) {//begin for String templetter = guessedletter; String tempword = BuildWord.charAt(cnt) //compares your one character guess to every character of the wordchosen if (guessedletter.charAt(0) == wordchosen.charAt(cnt)) { tempword = templetter; } else wrongt++; }//end for
thanks,

-Sondra
Reply With Quote
Sponsored Links