Hello,

I have a program I am working on that is working, except for the output for the avg. I know NaN can occur when the denominator is a zero, but mine are not zeros. Here is the relevant code.

``````double avg6 = (grade6tot/cont6Count);    // grade_tot's are declared as double,
double avg7 = (grade7tot/cont7Count);   //  cont_count's are declared as int.
Console.WriteLine("Grade Level    # of Contribs    Total Amount    Average");

Thanks a bunch.

It is working perfect with me actually what's the problem you are mentioning? I have tried taking input from user it also is working. Is this the way you are giving input to this program?

``````double grade6tot, grade7tot, grade8tot;
int cont6Count, cont7Count, cont8Count;
Console.WriteLine("Enter Total amount for 6th Grade:");
Console.WriteLine("Enter No. of contribs for 6th Grade:");
Console.WriteLine("Enter Total amount for 7th Grade:");
Console.WriteLine("Enter No. of contribs for 7th Grade:");
Console.WriteLine("Enter Total amount for 8th Grade:");
Console.WriteLine("Enter No. of contribs for 8th Grade:");

Here is my entire code.

``````namespace Contributions
{
class contributionProgram
{
static void Main(string[] args)
{
int cont6Count = 0;
int cont7Count = 0;
int cont8Count = 0;
double contrib = 0;
double totContrib = 0;

{
Console.WriteLine("(Enter 999 to quit):");
{
}

{
case 6:
cont6Count += 1;
break;
case 7:
cont7Count += 1;
break;
case 8:
cont8Count += 1;
break;
case 999:
{
}

{
}
{
}
Console.WriteLine("Grade Level    # of Contribs    Total Amount    Average");
Console.WriteLine("Your winning contribution was {0:c}", totContrib);
break;

default:
break;
}  //end switch

}  //end while
}

}
}``````

My output is something like this:
Grade Level # of contrib Total Amount Average
etc...

Why am I getting NaN for the division?

because you are calculating your average before taking input from user place this code

``````double avg6 = (grade6tot/cont6Count);
``````Console.WriteLine("Grade Level    # of Contribs    Total Amount    Average");