Calculations coming out to 0.0?
Posted
by Nick Gibson
on Stack Overflow
See other posts from Stack Overflow
or by Nick Gibson
Published on 2010-06-03T15:40:03Z
Indexed on
2010/06/03
15:44 UTC
Read the original article
Hit count: 133
A simple percentage calculation. It wont return a value except 0.0 and I think once or twice it returned 100.0%. Other than that it won't do a thing. I have tried playing with the code in several different ways and it just wont work.
for (int loop = 1; loop < loopCount; loop++)
{
aa = r.nextInt(10+1);
abc = (int) aa;
String[] userAnswer = new String[x];
int totalQues = (correctAnswer + wrongAnswer), actualQues = (totalQues - 1);
if(abc < x)
{
userAnswer[abc] = JOptionPane.showInputDialog(null,"Question "+quesNum+"\n\n"+questions[abc]+"\n\nA: "+a[abc]+"\nB: "+b[abc]+"\nC: "+c[abc]+"\nD: "+d[abc]+"\nCorrect Answers: "+correctAnswer+"\nWrong Answers: "+wrongAnswer+"\nTotal Questions: "+totalQues);
if(userAnswer[abc].equals(answers[abc]))
{
correctAnswer++;
}
else
{
wrongAnswer++;
}//else
if(actualQues == x);
{
score = (correctAnswer / actualQues) * 100;
JOptionPane.showMessageDialog(null,"The test is finished.");
JOptionPane.showMessageDialog(null,"You scored "+score+"%");
}//if
}//if
}//for
© Stack Overflow or respective owner