0
我遇到了麻煩,我已經閱讀了其他論壇關於這個問題的網站,但他們並沒有真正涉及到我的情況。我是C++的新手,我幾乎只有3周左右的時間。我不知道爲什麼我的break語句不起作用,對我來說這是在循環中。我錯過了什麼?Break語句不在循環語句或switch語句中?
float a[60][7];
int row;
cout << "How many students would you like to grade?" << endl;
cin >> studentNum;
cout << "Enter grades for the first student" << endl;
row = 0;
n = studentNum - 2;
while (row < studentNum)
{
a[row][0]=k;
a[row][0] = row;
cout << "Enter grade for test 1: ";
cin >> a[row][1];
cout << "Enter grade for test 2: ";
cin >> a[row][2];
cout << "Enter grade for test 3: ";
cin >> a[row][3];
cout << "Enter grade for test 4: ";
cin >> a[row][4];
a[row][5] = (a[row][1] + a[row][2] + a[row][3] + a[row][4])/4;
a[row][6] = a[row][1] * 0.2 + a[row][2] * 0.3 + a[row][3] * 0.3 + a[row][4] * 0.2;
row++;
}
if (row == n)
{
cout << "Enter Grades for the last Student" << endl;
cout << "Enter grade for test 1: ";
cin >> a[row][1];
cout << "Enter grade for test 2: ";
cin >> a[row][2];
cout << "Enter grade for test 3: ";
cin >> a[row][3];
cout << "Enter grade for test 4: ";
cin >> a[row][4];
break;
}
else
{
cout << "Enter grades for the next student" << endl;
row = row + 1;
}
cout << "Stdnt" << "\t" << "Grade1" << "\t" << "Grade2" << "\t" << "Grade3" << "\t" << "Grade4" << "\t" << "Avg1" << "\t" << "Avg2" << endl;
printarray(a, studentNum);
cin.get();
return 0;
你想在'if'結尾使用'break'來達到什麼目的? – Michael
我真的很感激這個幫助,我正在網上學習,但我知道這是一個錯誤,我的教授。將不會回覆我的電子郵件:( – frank104
@邁克爾我想要聲明「爲最後一名學生輸入成績」以結束與最後一名學生的成績,但就目前而言,當我運行該程序時,「爲成績輸入最後一個學生「甚至不會彈出,並且」爲最後一個學生輸入成績「出現在程序的最底部 – frank104