c ++禁止指针和整数之间的比较

时间:2015-03-07 12:22:47

标签: c++ arrays char

我对此代码有疑问 错误说ISO c ++禁止指针和整数之间的比较

这是运动问题 - 真正的错误测试的答案如下TTFFT给出一个二维答案数组,其中每一行对应于一个测试提供的答案,写一个接受二维数组的函数和测试的数量作为参数并返回一个包含每个测试成绩的一维数组(每个问题值5分,以便最大可能等级为25)

任何答案都会有所帮助。

这是代码

#include <iostream>

using namespace std;

int numberofgrades(char [][5], int []);

int main()
{
char testanswers[5][5] = {0};
int testgrades[5] = {0};
int counting1, counting2, counting3;

counting1 = 1;
counting2 = 1;
counting3 = 1;

cout << "this program will record the testgrades you entered: "
     << endl;

for(int i = 0; i < 5; i++)
{
    for(int k = 0; k < 5; k++)
    {
        cout << "enter answers for test no. " << counting1  << ": ";
        cin >> testanswers[i][k];
    }
    counting1++;
}

numberofgrades(testanswers,testgrades);



cout << "testing..." << endl;
cout << endl;

for(int o = 0; o < 5; o++)
{
    cout << "test no. " << counting2;
    for(int l = 0; l < 5; l++)
    {
        cout << " " << testanswers[o][l];
    }
    counting2++;
    cout << endl;
}

cout << "testing...." << endl;

cout << endl;

cout << "the total number of scores per test no. is: "
     << endl;

for(int t = 0; t < 5; t++)
{
    cout << "test no. " << t << ": " << testgrades[t] << endl;
}

return 0;
}

int numberofgrades(char t1a [][5], int tg1[])
{
for(int j = 0; j < 5; j++)
{
    for(int i = 0; i < 5; i++)
    {
        if(t1a[i] == 't') //this is the problem
        {
        tg1[j] = tg1[j] + 5;
        }
        else if(t1a[i] == 'T')
        {
        tg1[j] = tg1[j] + 5;
        }
        else if(t1a[i] == 'f')
        {
        tg1[j] = tg1[j] + 0;
        }
        else if(t1a[i] == 'F')
        {
        tg1[j] = tg1[j] + 0;
        }
        else{
            cout << "invalid letter exiting the program"
                 << endl;
                 return 0;
        }
    }
    }

 return tg1[5];
}

0 个答案:

没有答案