I have a little problem in my java application.
I have to calculate the score they have when they finish, I use this method:
public Float ScoreProcent(in
Try this:
num = (float) (100 * (float) correct / (float) questions);
or
num = (correct * 100.0) / questions;
There are no unreasonable quesions.
You are calculating what fraction of correct
are there among the questions
. The mathematical way of saying this is:
correct/questions
Now, since they can go onto decimals you need to use that Float
s you mentioned in your code. So:
(float)correct/(float)quesions
That is how you cast
something to float. To get the answer in percentage(in 100) it must be multiplied by 100 which is
100 * (float)correct/(float)quesions
And there you go :)
For proper way to get it coded listen to other answers.