它是我的输入输出还是其他导致问题的东西。我对C++非常陌生,所以如果事情很简单,我很抱歉。如果您需要更多信息,我已经在代码中包含了更多关于该问题的细节。当我尝试输出二维数组时,它输出错误的数字。
#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