Hey guys and girls.

Im working on a program at the moment, the aim of which is to determine a users age level (by year at school), and give them a set of randomly generated maths problems based on their age (eg- 1st grade only has to deal with numbers between 1 and 10, and plus and minuses. While 7th grade has to deal with numbers between -999 and 999 in addition subtraction multiplacation and division).

Iv got the basic code of the program working (via the use of several switches), but have been stumped on one of the final parts of the task. I have to add a help command. So instead of inputting the correct awnser the user imputs the letter 'h' and gets a hint towards the answer.

Example -
100 + 99 = 'h' (the correct answer being 199)
##9 (this is what i want the program to output after h has been imputted)
h
#99 (and if h is inputted again another number is revealed)
h
199 (h can be continously entered until the correct awnser is revealed)

From what iv gathered I have to convert the intiger i have set up for the answer into a string, but from there im stumped, iv looked up several 'guessing' games where blanked out letters are unblocked as the correct letter is imputted but im unable to find anything that will continuely unblock numbers on the fashion I need unforchantly.

Any help on this will be greatly appriciated.

Lokth,
can't you put an if statement saying if input equals h then give hint?

Something like,

String inputString = String.valueOf(input);
if (inputString == "h") {
// give hint function
}

I know it's pretty general but you'll have to give us your code for more specifics.


______________
Please, mark the problem as solved if you got an answer, thank you.

use equals method

String inputString = String.valueOf(input);
if (inputString.equals("h")) {
// give hint function
}
    switch (arithmatic2) {
        case '+': arithmatic3 = (number1 + number2); break;
        case '-': arithmatic3 = (number1 - number2); break;
        case '*': arithmatic3 = (number1 * number2); break;
        case '/': arithmatic3 = (number1 / number2); break;
       } 
       awnser = arithmatic3;

       awsnerString == awsner.toString();

       Scanner mathscan = new Scanner (System.in);
       mathscan = scan.nextLine();


   //    if (mathscan.hasNextInt()) 
   //    {guess = mathscan.nextInt();
   //    } else {
   //        System.out.println("Error - Enter a numeric value");
   //        System.exit(1);
   //    }

       if (guess == awnser)
       {correct = correct + 1;
           System.out.println("Correct");
       }else{incorrect = incorrect + 1;
           System.out.println("Incorrect");
       }

ok, heres part of the code (the entrie thing is huge).

int number1 and int number2 are both randomly generated and a earlier switch in the code determined if a + - * or / was generated.

the area im focusing on is the bit in bold, saldy my knowedge of strings is limited, from what iv workout i need something maybe along the lines of this

awsnerString == awsner.toString();

Scanner mathscan = new Scanner (System.in);
           mathscan = scan.nextLine();

Edited 3 Years Ago by mike_2000_17: Fixed formatting

stuffed that post up, anyway as i was typing. the code should look something along the lines of this?

awsnerString == awsner.toString();

Scanner mathscan = new Scanner (System.in);
mathscan = scan.nextLine();

if string awsnerString == 'h'
{ //I have no idea >< }

Lokth,
a possible solution could be to put every digit of your int answer variable on a int[] (to do that you could divide the number by 10, put the modulus on the array, divide again the result by 10 and so on).
That way you'll have every digit of your answer separated and you can show it in the order you want.
Don't take this as the best solution, perhaps (most probably) a more senior member will tell you a better one.


_______
Please, if you have an answer mark the problem as solved. Thanks.

This article has been dead for over six months. Start a new discussion instead.