评分程序中的两个错误

时间:2014-12-08 22:52:13

标签: c++ arrays

这是我的两个错误:

  • 错误C2664:'StudentMax':无法将参数1从'int'转换为'int []'
  • 从整数类型转换为指针类型需要reinterpret_cast,C风格的转换或函数式转换

这是我的代码,我需要修复什么?

// This program reads in data from a txt file, puts them in an array and calculates grades using that data.
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <fstream>
#include <string>

using namespace std;

    float lab1, lab2, lab3, lab4, lab5, lab6, lab7, lab8, lab9, lab10;
    float hw1, hw2, hw3, hw4, hw5, hw6, hw7, hw8;
    float midterm = 3*(midterm);
    float finall = 4*(finall);
    float labScore;
    float labAvg;
    float hwScore;
    float hwAvg;
    float finalGrade;
    string letterGrade;
    string studentNameFirst;
    ifstream inFile;

// prototypes for arrays
const char* names[10] = // kids names
{
    "Mike",
    "Carol",
    "Greg",
    "Marcia",
    "Peter",
    "Jan",
    "Bobby",
    "Cindy",
    "Alice",
    "Sam"
};
int* averages[10]; // number grades
string KidsLetterGrades[10]; // letter grades
int scores[4] = //elements comprising the final grade
{
    labAvg,
    hwAvg,
    midterm,
    finall
};

// function prototypes

int lowestScore(int scores[]);  
int StudentMax(int scores[]);   
void ComputeCourseGrade(int* averages[], string KidsLetterGrades[]);    
void PrintInfo(const char* names[], string KidsLetterGrades[], int* averages[]);




int main(){




    inFile.open("inputGrades.txt", ios::in); // opens input file

        if (!inFile)
        {
            cout << "Cannot open input file. "; // file not open
            return 1;
        }



    while (!inFile.eof( )) // until file ends
    {
        inFile >> studentNameFirst >> lab1 >> lab2 >> lab3 >> lab4 >> lab5 >> lab6 >> lab7 >> lab8 >> lab9 >> lab10 >> hw1 >> hw2 >> hw3 >> hw4 >> hw5 >> hw6 >> hw7 >> hw8 >> midterm >> finall;


    ComputeCourseGrade(averages, KidsLetterGrades);

    PrintInfo(names, KidsLetterGrades, averages); 

    }

    return 0;
}

void ComputeCourseGrade(int* averages, int scores[], string letterGrade)
{
    for(int i = 0; i < 10; i++)
    {

    labScore = .2*((lab1 + lab2 + lab3 + lab4 + lab5 + lab6 + lab7 + lab8 + lab9 + lab10)/100)*100;

    labAvg = (lab1 + lab2 + lab3 + lab4 + lab5 + lab6 + lab7 + lab8 + lab9 + lab10)/10;

    hwScore = .1*((hw1 + hw2 + hw3 + hw4 + hw5 + hw6 + hw7 + hw8)/80)*100;

    hwAvg = (hw1 + hw2 + hw3 + hw4 + hw5 + hw6 + hw7 + hw8)/8;


    finalGrade = ((labScore) + (hwScore) + (midterm) + (finall)); //attempting to make the lowest grade of the 4 things = to full credit for that grade aka dropping the lowest grade.... ideas on how?

    lowestScore(scores);

    finalGrade = finalGrade - lowestScore(scores);

    finalGrade = finalGrade/4;

    finalGrade = averages[i]; //assigns final grade in number form to array elements of average

    if ( finalGrade >= 90)
        letterGrade = "A";

        else if (finalGrade >= 85)
        letterGrade = "A-";

        else if (finalGrade >= 80)
        letterGrade = "B+";

        else if (finalGrade >= 75)
        letterGrade = "B";

        else if (finalGrade >= 70)
        letterGrade = "B-";

        else if (finalGrade >= 65)
        letterGrade = "C+";

        else if (finalGrade >= 60)
        letterGrade = "C";

        else if (finalGrade >= 55)
        letterGrade = "C-";

        else if (finalGrade >= 50)
        letterGrade = "D+";

        else if (finalGrade >= 45)
        letterGrade = "D";

        else if (finalGrade >= 40)
        letterGrade = "D-";

        else letterGrade = "F";

        letterGrade = KidsLetterGrades[i]; // assigns letter grades to array elements for kids letter grades
    }

    return;
}
int StudentMax(int averages[]) // to find student with highest class grade
{

     int max = averages[0];
    for( int m = 0; m < 10; m++)
    {
        averages[m];
          if(averages[m] > max)
          { // finds maximum number among array elements
              max = averages[m];
          }
    }
    return max;
}
void PrintInfo(const char* names[], const char* KidsLetterGrades[], int averages[])
{

    int count = 0;
    StudentMax( averages[count]);
    while (count < 10)
    {
        names[count];
        cout << names[count] << KidsLetterGrades[count] << StudentMax( averages) << endl; 
    }
    count++; // prints names then letter grades then averages
    return;
}
int lowestScore(int scores[])
{
    int lowest = scores[0];
    for( int n = 0; n < 4; n++)
    {
        scores[n];
          if(scores[n] < lowest)
          {
              lowest = scores[n];
          }; //finds lowest number among array elements
    }
    return lowest; 
}

1 个答案:

答案 0 :(得分:0)

您将int传递给StudentMax,其中需要一个数组(int[])。

您目前有StudentMax( averages[count]);,这是违规行。但是,你没有对这个结果做任何事情,所以只需删除该行。这应该可以解决这两个错误。