CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2013
    Posts
    1

    Guessing Game project

    So I'm supposed to make a 'how many jelly beans in the jar' guessing game. A few people guess and the winner is outputted while also showing how close or far they were.
    I'm having trouble with the output of how far the user was from the number of jelly beans in the jar:

    Code:
    do 
    			{
    				// Enter guess
    				System.out.print(playerName[i] + ", Enter your guess between 1000 and 2000: ");
    				playerGuess[i] = input.nextInt();
     
    			} while (playerGuess[i] <= 1000 || playerGuess[i] >=2000);	
    		}
    		
    	int howClose = jellyNum - playerGuess.length;

    And also it outputs everyone as being the winner:

    Code:
    for (int i = 0; i < playerGuess.length; i++)
    	{
    		if (playerGuess.length == jellyNum)
    		{
    			System.out.println("\nWinner is " + playerName[i] + " who guessed " + playerGuess[i] + ". Spot on! That is the exact # of jelly beans in the jar!");
    			System.out.println("\nYou were " + howClose + " of " + jellyNum + " jelly beans");
    		}
     
    		else if (playerGuess.length > jellyNum || playerGuess.length < jellyNum)
    		{
    			System.out.println("\n Winner is " + playerName[i] + " with a guess of " + playerGuess[i] + ", only " + howClose + " jelly beans away! Congrats!");
    		}
    Any tutorials I can watch or is this a small stupid problem I am not seeing

  2. #2
    Join Date
    Dec 2013
    Posts
    14

    Re: Guessing Game project

    Hello,

    It seems like you are holding playerGuesses in an array but you do not keep how close they are in a seperate array. That could be the problem.

    If not, please send the whole code so I can inspect more carefully for you!

    Good luck.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured