(sorry i miss-typed dev c++ IDE)
hi,
i am a CS class right now, and my professor uses VS 2010. I on the other hand am cheap, and i opted to get dev c++ as a Integrated developing environment. I wrote this code for a project due tomorrow and it works fine for dev c++, but does not compile for VS. I need help figuring out what is wrong. Can anyone convert this so it can work for Visual studios?
thank you:
#include <iostream>
#include <fstream>
#include <iomanip>
#include<math.h>
using namespace std;
float array[100]; // 100 is maximum amount of numbers in the file
int size = 0;
float myMean(float meanArray[],int N);
float mySd(float sdArray[],int N);
// This function verifies to see whether the file exists or not
bool check_file(string filename)
{
ifstream ListNumbers;
ListNumbers.open(filename.c_str(),fstream::in);
if (ListNumbers.good())
{
ListNumbers.close();
return true ;
}
return false;
}
// This function reads the file and stores the number in an array
int read_file()
{
ifstream filenumbers;
string filename;
int i=0;
float numbers;
cout << "Enter the name of the file: " << endl;
cin >> filename;
if (check_file(filename)==true)
{
filenumbers.open(filename.c_str(),fstream::in);
while (!filenumbers.eof()) // Keeps reading the file until it ends
{
filenumbers >> array[i];
if (filenumbers)
{
size++;
i++;
}
}
cout<<"The numbers in the input file are: "<<endl;
for (int i=0;i < size ; i++)
{
cout << array[i] <<endl;
}
cout<<"Total number of elements in the input file are: "<<size<<endl;
return 0;
}
filenumbers.close();
}
int main()
{
read_file();
float mean=myMean(array, size); //call to mean function.
float standardDeviation=mySd(array,size); // call to standard deviation function.
cout<<"The mean is: "<< mean<<endl; //mean output to console
cout<<"The Standard Deviation is: "<<standardDeviation; //standard deviation output to console
//output to file
ofstream fout("DataStats.txt");
if(!fout)
{
cout << "Cannot open output file.\n";
return 1;
}
fout << "The mean is: "<< mean<<endl; //mean output to file
fout << "The Standard Deviation is: "<<standardDeviation<<endl; //standard deviation output to file
fout.close();
cout<<endl<<"Press any key to exit...";
char c;
cin>>c;
return 0;
}
float myMean(float meanArray[],int N)
{
float sum=0;
for(int i=0;i<N;i++)
{
sum=sum+meanArray[i];
}
return (sum/N);
}
float mySd(float sdArray[],int N)
{
float avg =myMean(sdArray, N);
float sum=0;
for(int i=0;i<N;i++)
{
sum=sum+((sdArray[i]-avg)*(sdArray[i]-avg));
}
sum=sum/N;
float stdev ;
stdev= pow(sum,0.5);
return (stdev);
}