該指數是我需要解決的方案:返回值最大
編寫一個程序,要求用戶輸入由10個不同的人(
Person 1, Person 2, ..., Person 10
)吃過早餐薄煎餅的數量。
一旦輸入數據,程序必須分析數據並輸出哪個人吃了早餐最多的煎餅。
任何人可以寫返回值最大的指數的代碼(我已經標記爲 「H」)
#include "iostream"
using namespace std;
int main()
{
int x[11];
int y;
int h;
for (int i = 1; i <= 10; i++)
{
cin >> i[x];
cout << "Person: " << i << " has eaten " << i[x] << " pancakes" << endl
y = x[0];
h = x[0];
for (int j = 1; j <= 10; j++)
{
if (x[j] > y)
{
y = x[j];
}
}
}
cout << "The most pancakes are eaten by Person " << h << " with " << y << endl;
system("pause");
return 0;
}
_'Could anybody write the code for returns the index of maximum value'_ Certainly no!這是**你的**作業! –
這個問題有什麼困難?你應該能夠在整個互聯網上找到資源。 – bblincoe
如何首先使用比x,y和h更具描述性的變量重新標記變量?可以使你的邏輯樹更容易工作 – tinkertime