4

I'm getting errors on lines 102, 115, and 128. What am I doing wrong? It says:

Expected unqualified-id before numeric constant

and I don't know what that means. I've tried to fix this for a week now, and it's due in my C++ class this coming Wednesday. I could really use some outside advice here. What am I doing wrong:

#include <iostream>
#include <fstream>
#include <iomanip>
#include <conio.h>
#include <string>

using namespace std;

double qMeter = 0;
double hMeter = 0;
double oneMeter = 0;
int solDay = 0;
string garbage;
string localTime;
string decSol;
ifstream input;
ofstream output;

//function prototypes
double low(double lowTemp);
double high(double highTemp);
float average(double avgTemp);

int main()
{

input.open("curiosity234x.dat"); //opens input data file
output.open("output.dat"); //opens output data file


  for (int i = 0; i < 4; i++) //gets rid of the first four lines
{
  getline(input,garbage);
  cout << endl;
}

while (!input.eof())
{
    int count; 
    double newOneMeter;
    double newHMeter;
    double newQMeter;

    if (solDay == 2) //processes data for the second solar day
    {
     input >> solDay >> localTime >> decSol 
     >> newOneMeter >> newHMeter >> newQMeter;

     oneMeter = oneMeter + newOneMeter;
     hMeter = hMeter + newHMeter;
     qMeter = qMeter + newQMeter;
     count++;

     output << solDay << fixed << setprecision(1) << setw(5)
        << "Solar" << "Average" << "Low" << "High"
        << "Average" << "Low" << "High" 
        << "Average" << "Low" << "High" 
        << "Day" << "Temp" << "Temp" << "Temp" << "Temp" << "Temp"
        << "Temp" << "Temp" << "Temp" << "Temp"
        << fixed << setprecision(15) << "1 meter" << ".5 meters"
        << ".25 meters"
        << average(oneMeter) << low(oneMeter) << high(oneMeter)
        << average(hMeter) << low(hMeter) << high(hMeter)
        << average(qMeter) << low(qMeter) << high(qMeter);
    }

    if (solDay == 3) //processes data for the third solar day
    {
     input >> solDay >> localTime >> decSol 
     >> newOneMeter >> newHMeter >> newQMeter;

     oneMeter = oneMeter + newOneMeter;
     hMeter = hMeter + newHMeter;
     qMeter = qMeter + newQMeter;
     count++;

     output << solDay << fixed << setprecision(1) << setw(5)
        << "Solar" << "Average" << "Low" << "High" 
        << average(oneMeter) << low(oneMeter) << high(oneMeter)
        << average(hMeter) << low(hMeter) << high(hMeter)
        << average(qMeter) << low(qMeter) << high(qMeter);
    }
  }

  cout << endl << "The output.dat file has been written and transmitted.";
  /*
  reads first line. Assigns first string to 'int solDay' 
  second to 'string time', third to decSol, fourth to oneMeter, 
  fifth to hMeter and sixth to qmeter. Meters should have setw().
  */
getch();
return 0;

input.close();
output.close();
}


//functions used in main
double low(double lowTemp)
{
   int test = 10,000;
   double least;

   if (lowTemp < test)
   {
     lowTemp = test;
     lowTemp = least;       
    }
    return least;
}

double high(double highTemp)
{
   int test = 10,000;
   double most;

   if (highTemp < test)
   {
      highTemp = test;
      highTemp = most;        
    }
   return most;
}

float average(double avgTemp)
{
   avgTemp = avgTemp / count;
   return avgTemp;
}
Shafik Yaghmour
  • 143,425
  • 33
  • 399
  • 682
Brandon
  • 103
  • 2
  • 2
  • 10
  • 2
    [Don't use `while (!eof())`](http://stackoverflow.com/questions/5605125/why-is-iostreameof-inside-a-loop-condition-considered-wrong). – chris Feb 25 '13 at 04:31

2 Answers2

8

I searched this error when I ran into it. The cause of my troubles? I was trying to give a class the same name as #define value that had been included into my project from a 3rd party API header. Trying a different class name, I got it to compile!

Joel
  • 89
  • 1
  • 1
  • 3
    For whom is arrived here googling, like me, consider Joel answer. It also happened to me. I wanted to define const bool HIGH/LOW in a code that was including wiringPi.h libs for rasperryPi: unfortunatly wiringPi define (#define) HIGH/LOW... Thanks to Joel that make me have this suspect! – maxbeltra Mar 09 '14 at 15:26
  • @maxbeltra but unfortunately it does not answer this question. – Shafik Yaghmour Apr 13 '15 at 09:24
  • I've got the same problem and google for text "expected unqualified-id before numeric constant", well, this answer solves my problem. – pansz May 04 '15 at 02:01
4

Errors on line 102 and 115 are due to the fact that you have a comma in 10,000, but it should be 10000, the comma can not be used as a numeric separator. What you are actually using is the comma operator which evaluates it's expressions from left to right and only returns the last one. So in this case:

int test = 10,000;
           ^  ^
           |  Expression 2
           Expression 1

since = has higher precedence it happens first and your are left with a syntax error, on the other hand:

int test = (10,000);

would have resulted in the value 10 being discarded and octal literal 000 being assigned to test.

The final error on line 128 is due to the fact that count is local to main but you are trying to use it in average, you need to pass count as a second paramter.

Cedric Reichenbach
  • 8,157
  • 6
  • 50
  • 82
Shafik Yaghmour
  • 143,425
  • 33
  • 399
  • 682
  • 1
    The funny thing is that it actually compiles if you change it to `int test = (10,000);`. Of course that leaves `test` being 0, though. – chris Feb 25 '13 at 04:30
  • Should have added link to explanation of the comma operator, http://en.wikipedia.org/wiki/Comma_operator – Shafik Yaghmour Feb 25 '13 at 04:47