i got errors

hello.cpp:27: error: expected primary-expression before ??token
hello.cpp:29: error: expected primary-expression before ??token
hello.cpp:31: error: expected primary-expression before ??token

what's wrong!? help me!!

#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;
   count = 25;
   double data[25];

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

   getData(dataFile, data[], count);

   minMax(data[], count, min, max);

   numMeasures(data[], cout, mean, var);

   system("pause");
   return 0;
}



void minMax(const double data[], int count, double& min, double& max)
{
  ................
}

void numMeasures(const double data[], int count, double& mean, double& var)
{
  ................
}
   
void getData(fstream& dataFile, double data[], int& count)
{
  ................
}

Dani AI

Generated

Compiler message "expected primary-expression before ... token" usually means the parser hit something that is not an expression where one is required. In your case, VernonDozier nailed the big one: the [] belong in the function declaration/prototype, not in the call site. Passing data[] confuses the parser; just pass the array name so it decays to a pointer. jonsca also spotted a simple typo: you passed cout instead of count. Finally, as thousandpimps mentioned, make sure your argument types match the prototypes. You declared count as a double, but your functions take an integer count.

Two additional fixes will make the code compile cleanly and be easier to maintain:

  • Use an integer type for the element count (prefer std::size_t) and keep it consistent everywhere.
  • Your getData only reads; accept an input stream by reference (std::istream&) so you can pass an std::ifstream without type mismatch.

For example, update your signatures and calls like this:

// signatures
void getData(std::istream& in, double data[], std::size_t& count);
void minMax(const double data[], std::size_t count, double& min, double& max);
void numMeasures(const double data[], std::size_t count, double& mean, double& var);

// in main
std::size_t count = 25;
double data[25];

std::ifstream dataFile("sewage.data");
if (!dataFile) { /* handle error */ }

getData(dataFile, data, count);
minMax(data, count, min, max);
numMeasures(data, count, mean, var);

A few troubleshooting tips:

  • Always fix the first compile error first; later ones often cascade from it.
  • If a function will not modify the array elements, keep the const on array parameters (as you did for minMax and numMeasures).
  • Keep file paths relative to the program’s working directory, not the project location, to avoid false "file did not open" errors.

Recommended Answers

All 3 Replies

This isn't a code snippet. It's a regular thread.

getData(dataFile, data[], count);

Function calls shouldn't have the [] in them. Function prototypes do, but not function calls. Delete the [] in the function call and try recompiling.

On line 31 you are trying to pass "cout" instead of "count" to your method.

line 27 ur third parameter is double but in the prototype it is int

i think all ur errors are cuz of that, make sure ur var. type is the same when u call a function and what you have in ur function prototype

eg:

void readData(int, double, int);

readData(x,y,z)

ur x has to be an int, y had to be a double and z has to be an int

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.