Expected unqualified identifier before a numeric constant?

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

Expected unqualified identifier before a numeric constant

and I don’t know what that means. I tried to fix this for a week now and this should happen in my C ++ class this Wednesday. I could really use some external 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; } 
+4
source share
2 answers

The errors on lines 102 and 115 are due to the fact that you have a comma of 10,000 , but it must be 10000 , the comma cannot be used as a numeric separator. In fact, you are using a comma operator that evaluates its expressions from left to right and returns only the last one. So in this case:

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

since = has a higher priority, this happens first, and on your part there is a syntax error, on the other hand:

 int test = (10,000); 

would cause the value 10 be discarded and the octal literal 000 assigned to test .

The last error on line 128 is that count is local to main , but you are trying to use it in average , you need to pass count as the second parameter.

+4
source

I was looking for this error when I came across it. The cause of my problems? I tried to give the class the same name as the #define value, which was included in my project from a third-party API header. After trying a different class name, I got it to compile!

+4
source

All Articles