I need c++ help. Hi, I just created an average program just for fun. I use the do-while loop so its user can repeat the program as much as he/she likes. There has been one problem in my code. When the program is supposed to output the average, it outputs nan. Everything else is perfectly fine.
Here is the code.
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;
int main(int nNumberofArgs, char* pszArgs[])
{
char a;
long int nownum;
long double final;
long double numnum;
long double avrg;
long double accumulator;
do
{
cout << "\nThis program calculates the average of a group of numbers.\n";
cout << "How many numbers are you averaging? ";
cin >> numnum;
for (nownum = 1; nownum <= numnum; nownum++)
{
long double x = 0;
cout << "Enter number " << nownum << ": " ;
cin >> x;
accumulator += x;
}
avrg = accumulator/numnum;
final = avrg;
cout << "\nThe average is " << final << endl << "Thank You\n\n";
cout << "Would you like to put in a new set of numbers?\n" << "Put in y or n: ";
cin >> a;