0
void display_totals();
int exam1[100][3];// array that can hold 100 numbers for 1st column
int exam2[100][3];// array that can hold 100 numbers for 2nd column
int exam3[100][3];// array that can hold 100 numbers for 3rd column 
int main()
{
    int go,go2,go3;
    go=read_file_in_array;
    go2= calculate_total(exam1[],exam2[],exam3[]);
    go3=display_totals;
    cout << go,go2,go3;
    return 0;
}
void display_totals()
{

    int grade_total;
    grade_total=calculate_total(exam1[],exam2[],exam3[]);
}   
int calculate_total(int exam1[],int exam2[],int exam3[])
{
    int calc_tot,above90=0, above80=0, above70=0, above60=0,i,j;
    calc_tot=read_file_in_array(exam[100][3]);
    exam1[][]=exam[100][3];
    exam2[][]=exam[100][3];
    exam3[][]=exam[100][3];
    for(i=0;i<100;i++);
        {
            if(exam1[i] <=90 && exam1[i] >=100)
                {
                    above90++;
                    cout << above90;
                }
        }
        return exam1[i],exam2[i],exam3[i];

}

int read_file_in_array(int exam[100][3])
{
  ifstream infile;  

  int num, i=0,j=0;
  infile.open("grades.txt");// file containing numbers in 3 columns
    if(infile.fail()) // checks to see if file opended
    {
        cout << "error" << endl;
    }
  while(!infile.eof()) // reads file to end of line
      {
          for(i=0;i<100;i++); // array numbers less than 100
          {
            for(j=0;j<3;j++); // while reading get 1st array or element
            infile >> exam[i][j];
            cout << exam[i][j] << endl;
          }
      }
  infile.close();
  return exam[i][j];
}
4

2 に答える 2

1

calculate_totalに渡したデータ型が間違っています。C ++は、これをintへのポインターと見なしています。2次元配列を渡しています。calculate_total関数の入力タイプを配列のタイプと一致させる必要があります。

また、これらの余分な[]はすべて無効な構文です。配列として定義された変数を渡すときは、変数名のみを渡します。

// Invalid function call
f(myArray[]);

// Valid function call
f(myArray);

実際の機能の中で、あなたは何をしようとしていますか?Exam1、Exam2、Exam3の要素をexam [100] [3]の値に変更しようとしていますか?

配列の宣言もありませんint exam[100][3]。コードのどこにも表示されません。

そして、calculate_totalの戻り値では、returnステートメントの形式が正しくありません。3つの要素を含むタプルを返すPythonとは異なり、返すことができる値は1つだけです。

于 2010-04-29T04:15:41.830 に答える
0

コードで次の問題を確認しました

  1. read_file_in_array には括弧が必要です。go=read_file_in_array; //無効な関数呼び出し

  2. 配列を引数として渡す

  3. display_totals には括弧が必要です

  4. 最初に関数プロトタイプが欠落していた

  5. display_totals は何も返しません。しかし、あなたはそれを変数に割り当てています

  6. この calculate_total 関数が何をしているのかわかりません。

これがオリジナルのコードである場合、このコードには多くの問題があります。このコードをそのまま使用し、Turbo C++ コンパイラを使用してコンパイルしました。約24個のエラーが発生しました。

コードをリファクタリングしてコンパイルしてください。

于 2010-04-29T05:19:28.687 に答える