d2jsp
d2jsp Forums > Programmer's Haven > Java, Visual Basic, VBScript > How To Fix My Code?
Add Reply New Topic New Poll
ferf
#1 May 21 2020 08:09pm
Group: Member
Posts: 30,339
Joined: Mar 25 2009
Gold: 0.00
https://github.com/ferfykins/FerfsMathGame/blob/master/src/com/company/FerfsMathGame.java

(EDIT: btw don't pay attention to other classes, they're not important)



Basically, not sure what to do about this code specifically:
Code
public static int numCorrect;
public static int numWrong;
public static int totalQuestions = numCorrect + numWrong;
public static float percentCorrect = (float) numCorrect / totalQuestions;





i get NaN when getting percentCorrect variable..... also i tinkered with it
and tried this:
Code
public static int numCorrect;
public static int numWrong;
public static int totalQuestions = 1+numCorrect + numWrong;
public static int percentCorrect = numCorrect / totalQuestions;
public static float percentCorrect = (float) numCorrect / totalQuestions;



but with this i always get 0%.......






^basically niether of these ways work as it should.... trying to find correct answers % percentage.... Thanks guys

This post was edited by ferf on May 21 2020 08:11pm
ferf
#2 May 22 2020 02:56pm
Group: Member
Posts: 30,339
Joined: Mar 25 2009
Gold: 0.00
Code is finished/working now.
Go Back To Java, Visual Basic, VBScript Topic List
Add Reply New Topic New Poll