我已經做了一個函數,將整數輸入轉換爲另一個整數,它返回。具體來說,它採用控制檯顏色,並返回與輸入具有相同背景的對應顏色,但使用白色字符。爲什麼這個函數沒有返回正確的值?
該函數總是返回255.出什麼問題了?
int convertColorToPlayerColor(int color)
{
int playerColor = 0;
if (color <= 15)
playerColor = 15;
else if ((color > 15) && (color <= 31))
playerColor = 31;
else if ((color > 31) && (color <= 47))
playerColor = 47;
else if ((color > 47) && (color <= 63))
playerColor = 63;
else if ((color > 63) && (color <= 79))
playerColor = 79;
else if ((color > 79) && (color <= 95))
playerColor = 95;
else if ((color > 95) && (color <= 111))
playerColor = 111;
else if ((color > 111) && (color <= 127))
playerColor = 127;
else if ((color > 127) && (color <= 143))
playerColor = 159;
else if ((color > 159) && (color <= 175))
playerColor = 175;
else if ((color > 175) && (color <= 191))
playerColor = 191;
else if ((color > 191) && (color <= 207))
playerColor = 207;
else if ((color > 207) && (color <= 223))
playerColor = 223;
else if ((color > 223) && (color <= 239))
playerColor = 239;
else if (color > 239);
playerColor = 255;
return playerColor;
}
哦哇,我真的很笨。謝謝。 –