help me~~~

what's wrong with it?!

#include <iostream>
#include <iomanip>
#include <cmath>
#include <fstream>

using namespace std;

void minMax(const double, int, double&, double&);
void numMeasures(const double, int, double&, double&);
void getData(fstream&, double, int&);

int main()
{
   double count, min, max, mean, var;
   double data[400];
   count = 25; 
   /* how can I 'count' the number of measurements read from the file?*/
   char file;

   cout<<"Enter the name of the data file>";
   cin>>file;

   ifstream dataFile;
   dataFile.open("file");
   if(dataFile.fail())
      {
         cout<<"file did not open, please check it"<<endl;
         system("pause");
         return 1;
      }

   cout<<endl;
   cout<<endl;
   cout<<"Descriptive Statistics"<<endl;
   cout<<"------------------------------"<<endl;

   while(dataFile)
   {
      getData(dataFile, data[], count);  //**error**//
   
      minMax(data[], count, min, max); //**error**//
   
      cout<<"Min:"<<setw(20)<<setprecision(4)<<min<<endl;
      cout<<"Max:"<<setw(20)<<max<<endl;
   
      float range;
      range = max - min;
      cout<<"Range:"<<setw(20)<<range<<endl;
   
      numMeasures(data[], cout, mean, var); //**error**//
         
      cout<<"Mean:"<<setw(20)<<mean<<endl;
      cout<<"Variance:"<<setw(20)<<var<<endl;
       
      float s_d;
      s_d = sqrt(var);
      cout<<"Standard Deviation:"<<setw(20)<<s_d<<endl;
   }
      system("pause");
      return 0;
}

void minMax(const double data[], int count, double& min, double& max)
{  
   min = data[0];
   max = data[0];
      
   for(int i=0; i<count; i++)
      {
         if(data[i] > max)
            max = data[i];
         else if(data[i] < min)
            min = data[i];
      }
}        
      
void numMeasures(const double data[], int count, double& mean, double& var)
{      
   double sum_mean = 0;
   for(int i=0; i<count; i++)
      sum_mean += data[i];
   mean = sum_mean / count;
      
   double sum_var = 0;
   for(int j=0; j<count; j++)
      sum_var += (data[j] - mean);
   var = sum_var / (count-1);
}  
   
void getData(fstream& dataFile, double data[], int& count)
{     
   int amountRead = 0;
   int max_read = 400;
   while(dataFile>>data[amountRead] && amountRead<max_read)
      amountRead++;
}

Recommended Answers

All 4 Replies

If it doesn't compile, providing the errors would really help because i don't feel like testing the code myself.

If it doesn't compile, providing the errors would really help because i don't feel like testing the code myself.

i put //**error**// next to the 'errors'

Try removing the [] at the data[] so just data

When you are passing an array, you only use the name of the array, you do not use the braces. If you use braces, the compiler thinks you are trying to pass a specific element.

This causes 2 errors:
1. you haven't identified the specific element you want
2. you are no longer passing an array, you're passing a single value

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.