I've been working on this code for a hangman game but have got a problem with it. The problem is that it only checks for the last letter of the secrect word.
Thanks in advance,
John.
public class HangmanGuts extends Frame
{
{
String CurWord = "";
String dashes = "";
int guesses;
guesses = 0;
int j;
int a;
int counter;
counter = 0;
String curChar = "";
String curCharDash = "";
String UserGuess;
String words[]={"Mountain", "Mole", "Locker", "Routier", "Grim", "Insult", "Indepedent", "Sandbag", "Proposal", "Cricket"};
a = (int)(Math.random() * 10);
CurWord = words[a];
dashes = "";
for (int i = 1; i<=CurWord.length(); i++)
dashes +="-";
System.out.println(CurWord);
System.out.println("Welcome to Hangman, type a letter and press enter");
public class runHangman
{
public static void main(String args[])
{
HangmanGuts a = new HangmanGuts();
}
}
09-17-2004, 01:57 PM
frodos bane
You have a ';' after the for loop...
for (int j=0; j <CurWord.length()-1; j++);
{
i reckon that could be it.;)
Also, you may want to lose the '-1' part from that loop or it wont check the final letter (as far as i can tell).
Hope that fixes everything.
09-17-2004, 02:10 PM
jh_london
Thanks for you help, I spent 2 hours scatching my head wondering why it wouldn't work:o