/**This program is a simple number guessing game 
using the random class */

import java.util.Scanner;
import java.util.Random;



public class numGuessing {

public static void main(String[] args) {

        Scanner input = new Scanner(System.in);
        Random rndm = new Random();

        int num = rndm.nextInt(50);
        int numGuess;

        System.out.println("Please try to guess a number 1 to 50 !");
        numGuess = input.nextInt();

        while (numGuess != rndm)    {
             if (numGuess < rndm)    {
                System.out.println("Too low. Try again !");
                numGuess = input.nextInt(); }
            if (numGuess > rndm)    {
                System.out.println("Too high. Tr again !");
                numGuess = inut.nextInt();  }
            if (numGuess == rndm)   {
                System.out.println("Great job. You guessed the correct                                  number.");  }}
        }}
    }

This code is suppose to find the random number the computer chooses, but it's giving me a (Incompatible operand types int and Random) error. how do i fix it? Thnx

Recommended Answers

All 2 Replies

rndm is your random number generator.
num (line 3) is the random number.
On line 7,8 etc you compare the guess with (the random number generator) when you should compare it with the random number.

Thank James...i see where my mistake is now...I appreciate it

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.