2017-11-13 2 views
-4

私はコーディングが初めてであるため、このコードの一部が厄介で、たぶん理解が難しいと思われます。プログラムは、ユーザーに5つのクラスと各クラスの5つのテストスコアを入力させ、次に関数を使用して、最も低いテストスコア、最も高いテストスコア、および各クラスのスコアの平均を求める必要があります。私はそこでそれぞれの機能を果たしました。次に、別の機能を使用してそれを表示する、私の問題があります。私はそれが簡単な修正だと思いますが、私がする必要があるのは、mainからdisplay関数を呼び出して表示させるだけですが、毎回構文エラーが出ます。私が言ったように、私はそれが簡単な修正になると思うが、わからない。どんな助けもありがとう!表示するにはこの機能を使用できません

あなたは問題の関数にパラメータを渡すを持って
#include "stdafx.h" 
#include <iostream> 
#include <string> 
#include <stdlib.h> 
using namespace std; 
int minfun(int lowest, int test[5][5]) 
{ 
    for (int a = 0; a < 5; a++) 
    { 
     for (int i = 0; i < 5; i++) 
     { 
      if (test[a][i] < lowest) 
      { 
       lowest = test[a][i]; 
      } 
     } 
    } 
    return lowest; 
} 

int maxfun(int highest, int test[5][5]) 
{ 
    for (int a = 0; a < 5; a++) 
    { 
     for (int i = 0; i < 5; i++) 
     { 
      if (test[a][i] > highest) 
      { 
       highest = test[a][i]; 
      } 
     } 
    } 
    return highest; 
} 

double classavg(double avg, int sum, int test[]) 
{ 
    for (int a = 0; a < 5; a++) 
    { 
     for (int i = 0; i < 5; i++) 
     { 
      sum = sum + test[a]; 
     } 
    } 
    avg = sum/5; 
    return avg; 
} 

void display(string classes[], int test[], int lowest, int highest, double avg) 
{ 
    minfun(lowest, test[5]); 
    maxfun(highest, test[5]); 
    classavg(avg, sum, test[5]); 
    for (int a = 0; a < 5; a++) 
     { 
     for (int i = 0; i < 5; i++) 
      { 
       cout << "=============================================================" << endl; 
       cout << "Displaying stats for " << classes[a] << endl; 
       cout << "Lowest test score for " << classes[a] << " is: " << lowest << endl; 
       cout << "Highest test score for " << classes[a] << " is: " << highest << endl; 
       cout << "The average for " << classes[a] << "is: " << avg << endl; 
       cout << "=============================================================" << endl; 
      } 
     } 
    //needs for loop to display stats for each class 
} 

int main() 
{ 
    const int max_test = 5; 
    int lowest = 100; 
    int highest = 0; 
    int sum = 0; 
    double avg = 0; 
    string classes[5]; 
    int test[5][5]; 

    cout << "Enter the name of your first class: "; 
    getline (cin,classes[0]); 
    cout << "Enter the name of your second class: "; 
    getline (cin, classes[1]); 
    cout << "Enter the name of your third class: "; 
    getline(cin, classes[2]); 
    cout << "Enter the name of your fourth class: "; 
    getline(cin, classes[3]); 
    cout << "Enter the name of your fifth class: "; 
    getline(cin, classes[4]); 
    cout << "=============================================================" << endl; 
    for (int a = 0; a <= max_test; a++) 
    { 
     for (int i = 1; i <= max_test; i++) 
     { 
      cout << "Enter score for test " << i << " in " << classes[a] << " : "; 
      cin >> test[a][i]; 
     } 
     cout << "=============================================================" << endl; 
    } 
    cout << "=============================================================" << endl; 
    display(lowest, highest, avg); 
    system("pause"); 
    return 0; 
} 
+0

このエラーはありますか? 'エラー:' int 'から' int(*)[5] 'への無効な変換[-fpermissive] minfun(最低、テスト[5]);' – Arash

+1

"問題があります。画面上で問題を指摘すれば、それはこの大きなコードを読んでみたいと考えている他の誰にも役立ちません。 –

+1

*これは私の問題です*あなたが実際に問題を説明している場合にのみ役に立ちます。*構文エラーが何であるか教えない限り、*毎回構文エラーを出す* *あなたの目の前で画面上に**表示されるので、あなたの投稿でも私たちにそれを提供することはできません。明らかに、構文エラーであることが分かっていたので、それを見たことがあります。あなたのコードと同じように、画面上のテキストです。 –

答えて

0

、私はあなたがそれを見てください.. ところで、私はあなたの変数が静的作られ、いくつかのエラーを固定...、 賞賛を働くようできました。..

#include <iostream> 
#include <string> 
#include <stdlib.h> 
using namespace std; 
static string classes[5]; 
static int test[5][5]; 
static const int max_test = 5; 
static int lowest = 100; 
static int highest = 0; 
static int sum = 0; 
static double avg = 0; 

int minfun(int lowest) 
{ 
    for (int a = 0; a < 5; a++) 
    { 
     for (int i = 0; i < 5; i++) 
     { 
      if (test[a][i] < lowest) 
      { 
       lowest = test[a][i]; 
      } 
     } 
    } 
    return lowest; 
} 

int maxfun(int highest) 
{ 
    for (int a = 0; a < 5; a++) 
    { 
     for (int i = 0; i < 5; i++) 
     { 
      if (test[a][i] > highest) 
      { 
       highest = test[a][i]; 
      } 
     } 
    } 
    return highest; 
} 

double classavg(double avg) 
{ 
    for (int a = 0; a < 5; a++) 
    { 
     for (int i = 0; i < 5; i++) 
     { 
      sum = sum + test[a][i]; 
     } 
    } 
    avg = sum/5; 
    return avg; 
} 

void display(int lowest, int highest, double avg) 
{ 
    minfun(lowest); 
    maxfun(highest); 
    classavg(avg); 
    for (int a = 0; a < 5; a++) 
     { 
     for (int i = 0; i < 5; i++) 
      { 
       cout << "=============================================================" << endl; 
       cout << "Displaying stats for " << classes[a] << endl; 
       cout << "Lowest test score for " << classes[a] << " is: " << lowest << endl; 
       cout << "Highest test score for " << classes[a] << " is: " << highest << endl; 
       cout << "The average for " << classes[a] << "is: " << avg << endl; 
       cout << "=============================================================" << endl; 
      } 
     } 
    //needs for loop to display stats for each class 
} 

int main() 
{ 


    cout << "Enter the name of your first class: "; 
    getline (cin,classes[0]); 
    cout << "Enter the name of your second class: "; 
    getline (cin, classes[1]); 
    cout << "Enter the name of your third class: "; 
    getline(cin, classes[2]); 
    cout << "Enter the name of your fourth class: "; 
    getline(cin, classes[3]); 
    cout << "Enter the name of your fifth class: "; 
    getline(cin, classes[4]); 
    cout << "=============================================================" << endl; 
    for (int a = 0; a <= max_test; a++) 
    { 
     for (int i = 1; i <= max_test; i++) 
     { 
      cout << "Enter score for test " << i << " in " << classes[a] << " : "; 
      cin >> test[a][i]; 
     } 
     cout << "=============================================================" << endl; 
    } 
    cout << "=============================================================" << endl; 
    display(lowest, highest, avg); 
    system("pause"); 
    return 0; 
} 
関連する問題