C++ Xcode错误:指针和双精度计数器之间的比较

C++ Xcode错误:指针和双精度计数器之间的比较,c++,arrays,xcode,pointers,C++,Arrays,Xcode,Pointers,我试图编写一个程序,使用一个数组来存储6个测试的分数,然后添加一条分数曲线,然后显示最终分数。我一直从Xcode得到一个错误,在for循环中存在“指针和整数('int'和double'*')之间的比较” #include <iostream> #include <iomanip> using namespace std; int main() { const int test = 5; //sets the number of tests dou

我试图编写一个程序,使用一个数组来存储6个测试的分数,然后添加一条分数曲线,然后显示最终分数。我一直从Xcode得到一个错误,在for循环中存在“指针和整数('int'和double'*')之间的比较”

#include <iostream>
#include <iomanip>
using namespace std;

int main() {

    const int test = 5;    //sets the number of tests
    double score[test];      //array to hold each tests score
    double curve;           //curve for the tests
    double finalScore;      //The final test scores after the curve is applied

    //Input scores of the tests
    cout << "Enter the scores for \n";
    for (int test = 0; test < score; test++)
    {
         cout << "test #" << (test+1) <<": ";
         cin >> score[test];
    }

    //input the curve
    cout << "\nAll of these tests will have the same curve applied."
    << "\nEnter the curve: ";
    cin >> curve;

    //display the modified test scores
    cout << "\nHere are the curve test scores:\n";
    cout << fixed << showpoint << setprecision(2);

    for (int test = 0; test < score; test++)
    {
        finalScore = score[test] + curve;
        cout << "Test #" << (test + 1) << ": " << setw(7) << finalScore <<      endl;
    }

    return 0;
}
#包括
#包括
使用名称空间std;
int main(){
const int test=5;//设置测试的数量
double score[测试];//保存每个测试分数的数组
双曲线;//用于测试的曲线
double finalScore;//应用曲线后的最终测试分数
//输入测试的分数

cout
double score[5]
定义一个double数组,并且
score
表示该数组第一个元素的地址;因此,它是一个指针,并且
int test=0;test
将整数值与指针值进行比较;因此错误/警告

nrOfTests
与用于迭代测试的变量区分开来,例如
test

const int nrOfTests = 5;    //sets the number of tests
double score[nrOfTests];      //array to hold each tests score

....

for (int test = 0; test < nrOfTests; test++) { 
    ...
}

....

for (int test = 0; test < nrOfTests; test++) { 
    ...
}
const int nrOfTests=5;//设置测试的数量
double score[nrOfTests];//保存每个测试分数的数组
....
对于(int test=0;test
你认为
test
有什么作用?
for(int-test=0;test
->
for(int-test=0;test<5;test++)
这并不能直接解决问题,但是使用名为
test
的数组大小和名为
test
的循环控制变量是相当令人困惑的。您需要运行从0到数组大小
test
的循环,并给循环控制变量一个不同的名称将使其更加清晰。或者,可能更好的是,使用gi让数组大小成为一个更好的名称。现在继续使用糟糕的名称
test
,您可能想要
for(int i=0;i
或类似的名称。但是,实际上,使用更好的名称!