それは私の入力出力か、問題の原因となっているものですか?私はC++には本当に新しかったので、単純なことがあれば事前に申し訳なく思っています。私はいくつかの詳細情報が必要な場合は、コード内の問題に関する詳細を含めました。出力を2次元配列にしようとすると、間違った数が出力されます。
#include <iostream>
#include <iomanip>
using namespace std;
void input(string names[],int grades[][3]){
for(int n=0;n<3;n++){//Enter 3 into the grade book
cout<<"Please enter student name "<<n+1<<endl;
cin>>names[n];
}
for(int r=0;r<3;r++){// Enter 4 grades for each of the 3 students you added to the grade book
cout<<"Please enter 4 grades for "<<names[r]<<endl;
for(int c=0;c<4;c++){
cout<<"Grade "<<c+1<<": ";
cin>>grades[r][c];
}
cout<<endl;
}
}
//ignore this it wil;l be used to average the grades later
void math(int grades[][3], double average[]){
}
//If I input these number just to test the program
//student 1: 1,1,1,1
//student 2: 2,2,2,2
//student 3: 3,3,3,3
//it give me
//student 1: 1,1,1,2
//student 2: 2,2,2,3
//student 3: 3,3,3,3
void output(string names[],int grades[][3],double average[],char letter[]){
for(int r=0;r<3;r++){
cout<<names[r]<<" ";
for(int c=0;c<4;c++){
cout<<grades[r][c]<<" ";
}
cout<<endl;
}
}
int main(){
int grades[2][3];
double average[2];
char letter[2];
string names [2];
input(names,grades);
math(grades,average);
output(names,grades,average,letter);
return 0;
}
'grades'が' int grades [] [3] 'として宣言されているときは、範囲外であるため、' grades [r] [3] 'を使用しないでください。 – MikeCAT