我的代碼是:ç簡單數組代碼是不能工作
#include <stdio.h>
int main(){
int i, choice;
int player [11] = {1, 2, 10, 13, 21, 22, 24, 25, 31,32, 33};
int points [11] = {60, 297, 11, 373, 154, 52, 555, 218, 29, 242, 257};
int games [11] = {33, 35, 12, 35, 35, 35, 35, 35, 22,35, 35};
int assists [11] = {64 , 27 , 2 , 112 , 23 , 3 , 53 , 39 , 4 , 15 , 9 };
int rebounds[11] = {30,134,3,122,85,43,210,58,17,211,169};
const char* names[11] = {
"Jaylon Tate","Joe Bertrand","Jaylon Tate","Tracy Abrams","Malcolm Hill","Mav Morgan","Rayvonte Rice","Kendrick Nunn","Austin Colbert","Nnanna Egwu","Jon Ekey"
};
printf("Number\tGames\tPoints\tAssists\tRebounds\n");
int bestplayerppg = 0;
int bestplayerapg = 0;
int bestplayerrpg = 0;
float bestppg = 0.0;
float bestapg = 0.0;
float bestrpg = 0.0;
float ppg [11] ;
float apg [11];
float rpg [11];
int bestIndexppg = 0;
int bestIndexapg = 0;
int bestIndexrpg = 0;
for (i=0; i<11; i++){
ppg[i] = (float)points [i]/(float)games [i] ;
apg[i] = (float)assists [i]/(float)games [i] ;
rpg[i] = (float)rebounds [i]/(float)games [i] ;
printf("%s \t %d \t %d \t %d \t %d \t %.1f ppg \t %.1f apg \t %.1f rpg\n", names[i], games[i], points[i], assists[i], rebounds[i], ppg[i], apg[i], rpg[i]);
if (ppg[i]>bestplayerppg){
bestplayerppg = player[i];
bestppg = ppg[i];
bestIndexppg = i;
}
if (apg[i]>bestplayerapg){
bestplayerapg = player[i];
bestapg = apg[i];
bestIndexapg = i;
}
if (rpg[i]>bestnorpg){
bestplayerrpg = player[i];
bestrpg = rpg[i];
bestIndexrpg = i;
}
}
printf("Pick the stat you want to view:\n1. Points per game\n2. Assists per game\n3. Rebounds per game\nEnter a choice: ");
scanf("%d",&choice);
printf("The player with the most ");
switch (choice){
case 1:
printf("points per game is #%d %s with %.1f ppg.\n", bestplayerppg, names[bestIndexppg], bestppg);
break;
case 2:
printf("assists per game is #%d %s with %.1f apg.\n", bestplayerapg, names[bestIndexapg], bestapg);
break;
case 3:
printf("rebounds per game is #%d %s with %.1f rpg.\n", bestplayerrpg, names[bestIndexrpg], bestrpg);
break;
default:
printf("Choice is not valid\n");
}
}
的代碼完全適用於得分和助攻。但是在找到頂級RPG時它不起作用。它說#13特雷西又名陣列中的第四個元素,當他沒有的時候,他的RPG最高。我的得分,助攻邏輯和籃板是一樣的,但只有得分和助攻工作...
第三,如果是錯誤 – mch 2014-10-12 02:53:44