1

Why does calcGPA keep saying it equals NaN? I make sure it is not undefined.

double gradesMultiplied = ((quantityA * 4.00) + (quantityAMin * 3.70) + (quantityBPlu * 3.30) + (quantityB * 3.00) + (quantityBMin * 2.70) + (quantityCPlu * 2.30) + (quantityC * 2.00) + (quantityCMin * 1.70) + (quantityDPlu * 1.30) + quantityD + (quantityDMin * 0.70));
double gradesAdded = (quantityA + quantityAMin + quantityBPlu + quantityB + quantityBMin + quantityCPlu + quantityC + quantityCMin + quantityDPlu + quantityD + quantityDMin + quantityF);
double calcGPA = gradesMultiplied / gradesAdded;
tchristofferson
  • 183
  • 1
  • 1
  • 14

2 Answers2

0

NaN is Not a Number, try explicitly converting all values to numbers in the beginning.

Also looking at this is it possible you are dividing zero by zero?

"NaN" stands for "not a number". "Nan" is produced if a floating point operation has some input parameters that cause the operation to produce some undefined result. For example, 0.0 divided by 0.0 is arithmetically undefined. Taking the square root of a negative number is also undefined.

Community
  • 1
  • 1
workabyte
  • 3,496
  • 2
  • 27
  • 35
0

I fixed it everybody. I had to put the first 2 lines in my methods that add the quantity when pushing button.

tchristofferson
  • 183
  • 1
  • 1
  • 14