Thread: My wordguess program won't work, can anyone check my code?????

  1. #1
    Registered User
    Join Date
    Dec 2011
    Posts
    1

    My wordguess program won't work, can anyone check my code?????

    okay so I am supposed to make this wordguess program and the here is my code:

    Code:
    import java.util.Random;
    import java.util.Scanner;
    
    
    public class Wordguess123 {
    public static String replaceCharAt(String s, int pos, char c) {
        return s.substring(0,pos) + c + s.substring(pos+1);
     }
     public static void main(String[] args){
            Scanner Jerry = new Scanner(System.in);
            Random Rong = new Random(10);
            String word;
            boolean guess = true;
            int i = 0;
            String win = "YOUWIN!!!!";
            System.out.println("This is Jerry Rong's wordguess game!");
            
            switch (Rong.nextInt()) {
                
                case 1: word = "PROPORTION";
                break;
                case 2: word = "DISTANCE";
                break;
                case 3: word = "MOMENTUM";
                break;
                case 4: word = "HELLO";
                break;
                case 5: word = "GRAPHIC";
                break;
                case 6: word = "ACCELERATION";
                break;
                case 7: word = "ENERGY";
                break;
                case 8: word = "NINJA";
                break;
                case 9: word = "FINALS";
                break;
                default: word = "CHRISTMAS";
                break;
         }
         
         int length = word.length();
         String blank = null;
         for (int h = 0; h < length; h++)
         {  blank = "_" + " ";}
         
         System.out.println(blank);
         String PeoplesGuess = blank;
         
         do {
          i++;
          String letter = in.next();
         letter = letter.toUpperCase();
         if (letter =! "!") {
         
            for (int k = 0; k < length; k++){
    
    
                        if (letter.charAt(0) == word.charAt(k)) {
                            current = replaceCharAt(current, k, letter.charAt(0));
                        }
                        
                    }
            
            if (current.equals(word)) {System.out.println("You win!!");     } 
            System.out.println ("you used" + i + "guesses ");
            System.out.println ("The secret word is" + word  );
                }
                
         else 
         {
             System.out.println("Guess the word in uppercase.");
             String guessedword = in.next();
             guess = false;
             if (guessedword.equals(word)) {System.out.println(win));}
             else System.out.println("Haha you lose");
             System.out.println ("you used" + i + "guesses ");
            System.out.println ("The secret word is" + word  );
             
             
            }
        
            
            
            
    }
    while ( i < 27 && guess = true);

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Perhaps you should have another guess at which language you're programming in.

    Because what you posted looks like Java, and this is a C++ board.

    What's more bizarre, we don't even have a Java sub-forum - so you must simply be lost at this point.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Nov 2011
    Posts
    63
    GCC must be giving you lots of errors!
    Anyways, this isn't a Java board, but I'll give you one quick tip.

    An error I see right away:

    Code:
    if (letter =! "!")
    If you're comparing references to Strings, then this should be:

    Code:
    if (letter != "!")
    If you're comparing two chars, this should be:

    Code:
    if (letter != '!')
    If you're comparing the contents of two Strings, then this should be:

    Code:
    if ("!".equals(letter))
    I didn't look at the rest of your program.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Please check my code
    By foxx2jett in forum C Programming
    Replies: 18
    Last Post: 04-25-2011, 12:00 PM
  2. Please check my work...
    By viciousv322 in forum C Programming
    Replies: 31
    Last Post: 12-18-2005, 11:50 PM
  3. Code doesn't work: Check alphabetical order
    By motozarkov in forum C++ Programming
    Replies: 5
    Last Post: 04-27-2005, 02:53 PM
  4. Replies: 10
    Last Post: 03-26-2003, 04:57 PM
  5. Check this code for pausing program
    By jordan6 in forum C++ Programming
    Replies: 6
    Last Post: 03-22-2002, 11:44 AM