1

So my problem is that if you want to get a new calculation, the operaotr in my array should change. How can i do that? im trying this now for hours :/ this is how far i got. so first it starts with + and whan you choose to get a new calculation the next one should be - and so on.... so i need to switch the "operator[0]"

private static void mathGame() {
        char[] operator = {'+', '-', '*', '/'};
        int x;
        int y = 0;
        Scanner input = new Scanner(System.in);

        do {
            int operand1 = (int) (Math.random() * (100 - 1) + 1);
            int operand2 = (int) (Math.random() * (100 - 1) + 1);
            System.out.println("Solve");
            System.out.println(operand1 + " " + operator[0] + " " + operand2);
            x = input.nextInt();
            // operator [1]++;
            if (x == evaluate(operand1, operator[0], operand2)) {
                System.out.println("True!");
                System.out.println("New Challange?");
                y = input.nextInt();
                //operator[1]++;
            } else if (x != evaluate(operand1, operator[0], operand2)) {
                System.out.println("False!");
                System.out.println("New Challange?");
                y = input.nextInt();
                //operator[1]++;
            }
        } while (y == 1);
    }
0

1 Answer 1

1

You need to define a variable outside of your loop (int i = 0;) and then have this instruction inside the loop (maybe before "} while (y == 1);":

i = (i + 1) % 4; (4 is size of your operators array).

p.s. I think you need to give more details about your question and elaborate your question in order to make it more clear for future readers.

Sign up to request clarification or add additional context in comments.

2 Comments

If it answers your question, please chose the answer as the right answer.
i always choose it but you have like a "5 min Cooldwon" on klicking it :/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.