#include <iostream>
#include <cctype>
#include <cstdlib>
#include <fstream>
#include <cmath>
usingnamespace std;
int main()
{
//Variable declarations
int input[25];
int count, sum=0;
double stdev, average, numerator;
ifstream fin;
ofstream fout;
//Check if files can be opened
fin.open("Lab7_input.txt");
if(fin.fail())
{
cout << "Cannot open Lab7_input.txt" << endl;
exit (0);
}
fout.open("Lab7_output.txt");
if(fin.fail())
{
cout << "Cannot open Lab7_output.txt" << endl;
exit (0);
}
fin.get(input[]);
while(fin.get(input[]) != -1)
{
sum += input[];
count++;
fin.get(input[]);
}
average = (sum/count);
for(int i=0; i<24; i++)
{
numerator += pow( (input[i] - average) , 2);
}
stdev = sqrt(numerator/count);
//Closing files
fin.close();
fout.close();
return 0;
}
Explanation would be nice if anyone decides to reply, thanks :)
PS: I'm not even looking for anyone to do it for me, just would like some help with it, can't seem to get it to work
being able to make this even run pretty much. clarification on how i should go about getting the input from the file to read into my array properly? And from there, getting the numerator variable to be calculated correctly. Basically array help in general, that's what's killing me here.
I probably should've included the text file the assignment refers to, here it is:
oh, sorry. basically read from the file "Lab7_input.txt" (posted above) , calculate the average, sum, and standard deviation of those values and write that into the output file "lab7_output.txt" (realize I didn't write a command for that yet, not troubled by it). The value -1 should stop the program from further reading from the file and should not be included in the calculations.
Cannot figure out how to get the value that is read to be put into the array "input" so that i can use indexing later to reference certain values when calculating for numerator
It's incredibly difficult to read an arbitrary number of values with those restrictions - is there an upper limit? e.g. can there be infinite numbers or only up to say 100?
Well, the issue is that your program may be tested with a shorter or longer input file, in which case problems would happen. Are you sure there's no upper limit?
In that case, I think you have to ditch the array. I am pretty sure it is possible to make the calculations without storing any of the numbers - just process them as you read them from the file.