Hey guys, I'm having trouble trying to set pounds as something you can compare the user's input to. I want it to put out the appropriate output if the user either guess it right or wrong. But I keep getting an error when I try to compile this. It says, cannot find symbol. symbol:variable pounds and then references the char answer3 = pounds line. Any way that you guys know how I can set it so that it compares the user's input to the correct answer pounds? The code is listed below on what I'm working on and then the whole class is listed below that so you can try compiling it for yourself. I'm about 1 month into a class on java and this is my first dealing with the user input so your help is greatly appreciated! I would also like for it to loop back and have them try again if the answer they put in is wrong. I don't really even know how to get started on that one, it's prolly something really simple, but I couldn't figure out how to do it. Thanks!
System.out.println("What 6-letter word can you make out of the letters d-u-n-o-p-s.");
char guess2 = reader.readChar();
char answer3 = pounds;
if (guess2 == answer3)
{
System.out.println("Hooray! You are correct!");
}
else
{
System.out.println("Sorry, the correct answer is pounds "+ answer3);
Here's the whole class.
import java.util.*;
public class TextShuffleInstructions
{
private CinReader reader;
public TextShuffleInstructions ()
{
reader = new CinReader();
}
public void start()
{
System.out.print("Hello, and welcome to the TextShuffle instructions game.");
System.out.print("To begin,please read the following so that you can answer the questions to follow.");
System.out.println("This is to make sure that you are able to understand how the game is played.");
System.out.println("");
System.out.print("Each round you are given 6 letters and from these letters you must guess all the 4-letter,5-letter and 6-letter words that come from those 6-letters. Each letter is worth 10 points. For example, if you guess a 4-letter word, you will get 40 points. If you guess the 6-letter word, you will get the letter points plus an extra 100 points. Once you have guessed all the words from the round, you will advance to the next round.");
System.out.println("");
System.out.println("");
System.out.println("");
System.out.println("");
System.out.println("");
System.out.println("How many points will you get if you guess the 6-letter word correctly?");
int guess = reader.readInt();
int answer = 160;
if (answer == guess)
{
System.out.println("Hooray! You are correct!");
}
else
{
System.out.println("Sorry, the correct answer is "+ answer);
}
System.out.println("How many points will you get if you guess a 4-letter word correctly?");
int guess1 = reader.readInt();
int answer2 = 40;
if (answer2 == guess1)
{
System.out.println("Hooray! You are correct!");
}
else
{
System.out.println("Sorry, the correct answer is "+ answer2);
}
System.out.println("What 6-letter word can you make out of the letters d-u-n-o-p-s.");
char guess2 = reader.readChar();
char answer3 = pounds;
if (guess2 == answer3)
{
System.out.println("Hooray! You are correct!");
}
else
{
System.out.println("Sorry, the correct answer is pounds "+ answer3);
}
}
public static void main(String[] args)
{
TextShuffleInstructions thisClass = new TextShuffleInstructions();
thisClass.start();
}
}