ok guys.... i have a multiple choice scenario to deal with.... my problem is in the division....both my
random numbers have been declared as integers.. this caused the problem of the answer being
truncated and only the whole number portion being displayed... i tried to cast one as a double but
it's not working...any suggestions....
for(counter = 1; counter <= 2; counter++) {
responseAns = false; correct = false;
Random_num1 = 1 + r.nextInt(25);
//Makes sure our second number is not bigger than our first number
do{
Random_num2 = 1 + r.nextInt(9);
}
while(Random_num1 < Random_num2);
correct_ans = Random_num1 / Random_num2;
incorrect_ans = correct_ans + Random_num2;
System.out.print("Question# " + counter + ": ");
System.out.println(Random_num1 + " / " + Random_num2 + " = ");
int position = r.nextInt(2);
if(position == 0)
{
A = correct_ans;
B = incorrect_ans;
}
else {
A = incorrect_ans;
B = correct_ans;
}
// difference = input.nextInt();
while (!correct) {
System.out.println("A " + A);
System.out.println("B " + B);
String response = input.next().toUpperCase();
if(position == 0)
{
if(response.equals("A"))
{
responseAns = true;
}
}
else
{
if(response.equals("B"))
{
responseAns = true;
}
}
if (responseAns) {
System.out.println("CORRECT! Great Work " + name);
count_correct_ans++;
points++;
correct=true;
} //END OF INNER IF
else {
chances--;
if(chances == 1){
display_chances = "chance";
}
else if(chances == 0){
System.out.println("Sorry you have lost. You do not have any more chances");
System.out.println("");
System.out.println("PLAYER'S NAME: " + name);
System.out.println("PLAYER'S AGE: " + age);
System.out.println("QUESTIONS ANSWERED: " + count_correct_ans);
System.out.println("POINTS MADE: " + points);
System.out.println("");
System.out.println("END OF GAME");
System.out.println("++++++++++++++++++++++++++++++++++++++++++++");
System.exit(0);
}
System.out.println("INCORRECT! Try again, " + chances + " " + display_chances + " Remaining");
System.out.println(Random_num1 + " / " + Random_num2 + " = ");
count_incorrect_ans++;
correct=false;
} // END OF INNER ELSE
}// END OF WHILE LOOP
} // END OF FOR LOOP
that's the working code with that displays only the whole number portion of the answer