它是我的輸入輸出還是其他導致問題的東西。我對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