我有两个数组:
int playerSums[9] = { };
string playerNames[9] = { };
Run Code Online (Sandbox Code Playgroud)
我试图获取数组中的最小值playerSums以及该值的数组索引。
到目前为止,这是我尝试过的:
if (playerNames[index] == "End" || playerNames[index] == "end") {
int lowestValue = playerSums[0];
for (i = 1; i < sizeof(playerSums) / sizeof(playerSums[0]); i++) {
if (playerSums[i] < lowestValue || lowestValue != 0)
lowestValue = playerSums[i];
}
cout << index[playerNames] << " had the lowest values and got the sum ";
cout << lowestValue << endl;
}
Run Code Online (Sandbox Code Playgroud)
playerSums例如,如果只有 3 个玩家在玩,即仅填充了数组的 …