4

我在线路上遇到错误102, 115, and 128。我究竟做错了什么?它说:

数字常量之前的预期不合格 id

我不知道那是什么意思。我已经尝试解决这个问题一周了,它将于本周三在我的 C++ 课上到期。我真的可以在这里使用一些外部建议。我究竟做错了什么:

#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

2 回答 2

8

当我遇到它时,我搜索了这个错误。我烦恼的原因是什么?我试图给一个与#define 值相同的名称,该值已从第 3 方 API 标头包含到我的项目中。尝试不同的类名,我得到了编译!

于 2013-08-29T03:22:37.190 回答
4

第 102 行和第 115 行的错误是由于您在 中有一个逗号10,000但应该是10000逗号不能用作数字分隔符。您实际使用的是逗号运算符,它从左到右评估它的表达式,并且只返回最后一个。所以在这种情况下:

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

因为=具有更高的优先级,它首先发生,另一方面,您会遇到语法错误:

int test = (10,000);

会导致该值10被丢弃并将八进制文字 000分配给test.

第 128 行的最后一个错误是由于 count 是本地的,main但您试图在 中使用它average,您需要count作为第二个参数传递。

于 2013-02-25T04:01:08.193 回答