I'm trying to create an android application which will be a simple maths game. It has Multiple Difficulty Levels including easy, medium, hard, Very Hard. Easy level involves the arithmetic question questions between 2 integers(6+6), Medium between 3(2+2-1), Hard between 4(2+2-1/3) and Very Hard between 5(2+3*5-3+2). I have to generate random Integers and random Arithmetic operations. I am able to display the questions and operations for each difficulty level but I can not find the correct Answer. Whatever answer I enter, the programme shows it incorrect. For Example if I answer 3+3-1 as 5 or any other it will always be shown wrong. For 2 Integers I used switch statements, and it worked fine, but the questions involving multiple Arithmetic operations always are wrong any Idea as how to do it. I am Putting the code below
private final int ADD_OPERATOR = 0, SUBTRACT_OPERATOR = 1, MULTIPLY_OPERATOR = 2, DIVIDE_OPERATOR = 3;
private String[] operators = {"+", "-", "x", "/"};
operator = random.nextInt(operators.length);
switch(operator)
{
case ADD_OPERATOR:
answer = operand1+operand2;
break;
case SUBTRACT_OPERATOR:
answer = operand1-operand2;
break;
case MULTIPLY_OPERATOR:
answer = operand1*operand2;
break;
case DIVIDE_OPERATOR:
answer = operand1/operand2;
break;
default:
break;
}
question.setText(operand1+" "+operators[operator]+" "+operand2);
//Operand 1 and Operand 2 are 2 Random Integers
I am storing the user answer as answeredtext. Any help as how to do it for multiple Arithmetic operations. Thanks
Aucun commentaire:
Enregistrer un commentaire