2011-09-03 58 views
0

我必須制定一個計劃,輸入10個學生的成績,並顯示他們的體重和未體重的平均值。我不熟悉C++編程,所以我不太瞭解,當人們使用他從未教過的東西時,我的教授不喜歡它。如何在C++ for循環後輸入值?

下面是代碼:它顯示爲什麼是學生1,2的四個考試分數等。當我說「什麼是學生1的四個考試分數」時,我該如何做它,然後我將能夠進入那些英寸然後到學生2,學生3等?

謝謝你的時間。

#include <iostream> 
using namespace std; 
const int numberofstudents = 10; 

int main() 
{ 

int student; 
for(student=1; student<=numberofstudents; student++) 
cout << "\nWhat are the four test scores of student number " << student << endl; 

return 0; 
} 
+1

鑑於你的評論,你到目前爲止涉及的是什麼? –

+0

你應該可以自己做到這一點。我希望你有你的課程的一些文件。如果沒有,使用谷歌找到一個C++的參考或教程。然後,想想!你需要一些變量(s?)來存儲數據,你需要用一個塊代替單行'for'主體(即添加'{'和'}'),然後把你的計算在那裏。您可能需要在第一個循環內添加第二個循環,具體取決於您解決此問題的方式。 – nobody

+3

告訴你的教授停止這樣做:'using namespace std;' –

回答

4

我想你想讀四個值每一個學生,如果是這樣,那麼理解這段代碼:

#include <iostream> 
using namespace std; 

int main() 
{ 
    const int numberofstudents = 10; 
    double scores[numberofstudents][4]; 
    for(int student=0; student<numberofstudents; student++) 
    { 
    cout << "\nWhat are the four test scores of student number " << (student+1) << endl; 
    int i = 0; 
    while (i < 4) 
    { 
     //scores is a two dimentional array 
     //scores first index is student number (starting with 0) 
     //and second index is ith score 
     cin >> scores[student][i]; //read score, one at a time! 
     i++; 
    } 
    } 
    //process scores... 
} 

現在,因爲它是你的家庭作業,做你的工作你自己的休息。祝一切順利!