因此,我編寫了一個程序,要求用戶輸入一個人(1-10)早餐煎餅的數量。該計劃必須分析輸入並確定哪個人吃了最多的煎餅。此外,程序必須按照所有10人所吃的煎餅數量的順序輸出一個列表。到目前爲止,我已經編寫了代碼來獲取用戶輸入和代碼來顯示數組,但不是按順序。進出口,當涉及到陣列中的比較要素完全喪失:如何比較數組內的值
int getPancakes();
void displayArray(int theArray[],int sizeOfArray);
void compareArray(int sizeOfArray);
int pancakes[10];
int z = 0;
int main()
{
}
int getPancakes(){
int y;
int x = 0;
for(int y = 0; y < 10; y++){
++x;
cout << "How many pancakes did person " << x << " eat?" << endl;
cin >> pancakes[y];
}
}
void displayArray(int theArray[],int sizeOfArray){
for(int x = 0 ;x < sizeOfArray ; x++){
++z;
cout << "Person " << z << " ate " << pancakes[x] << " pancakes" << endl;
}
}
所以,我怎麼能指導我的程序到陣列中的元素比較?另外,如何指導我的程序打印每個人吃的煎餅數量列表?
這功課嗎? – jterrace 2014-09-10 15:31:16
另外,如果您早餐吃了10個煎餅,您可能會遇到問題。 – jterrace 2014-09-10 15:31:40
我不明白。你使用'pancakes [x]'來訪問數組中的元素,但是你說你不知道如何比較數組中的元素的值?我錯過了什麼嗎? – 2014-09-10 15:41:33