Hi, I need help with a program i'm writting, where the user has to enter a file with numbers, and then after I need to work out the sum of the contents, the biggest number, smallest number and average. I'm using textpad 5, with compiler MinGW. I can get my program to show the contents, but the sum is completely wrong.
Any help would be useful
Thank you Liam.
// Read the data from the file into an array
cout << "These are the contents of the file: " << endl;
while (myfilein.good())
{
cout << (char) myfilein.get();
}
// Calculate and print results on screen.
/*
To do: remember to calculate max, min,
sum and mean using functions
*/
cout << endl << endl;
while (myfilein >> N)
{
sum = sum + N;
}
cout << "The sum of the contents the file is: " << sum << endl;
/* cout << "The maximum value of the file is: " << max << endl;
cout << "The minimum value of the file is: " << min << endl;
cout << "The mean value of the file is: " << mean << endl;
*/
return 0;
}
/*To do - function definitions*/
If you would like to see the rest the program you just have to ask.
Yes, I did, and the answer is 0. When I don't the answer is like 5e-10. I need to save the file contents (5 numbers) to an array, i think that may be the problem, but i don't know how to save it to an array.
Thanks Liam.