我想運行下面的代碼,但我正在進入一個循環,我不能出去。有人可以幫我解決我的while循環嗎?它一直在運行
應該出現的錯誤消息假設用戶能夠輸入正確的範圍值。
有人可以修復這個無限循環,以便它只有當使用輸入值超出範圍時纔會出現。
#include<stdio.h>
int main(void) {
int students, counter, total;
int marks[40];
int stdno[40];
total = 0;
printf(" ---=== IPC mark Analyser V2.0 ===---\n");
printf("Please enter the number of students(between 3 and 40):");
scanf("%d", &students);
while (students < 3 || students >40) {
printf("Invalid number, enter a number between 3 and 40 inclusive:");
scanf("%d", &students);
}
printf("Row Std No Mrk\n");
printf("--- --------- ---\n");
for (counter = 0; counter < students; counter++) {
printf(" _________ ___\r");
printf("%03d ", counter + 1);
scanf("%09d %3d", &stdno[counter], &marks[counter]);
while (marks < 0 || marks >100 || stdno < 10000000 || stdno > 999999999) {
printf("Error: Enter values between 0 and 100 inclusive.\n");
scanf("%09d %3d", &stdno[counter], &marks[counter]);
}
return 0;
}
}
請格式化您的代碼首先正確。 –
您的代碼格式太差,無法閱讀此問題。 – Lundin
編譯所有啓用的警告,閱讀編譯器吐出的警告並將它們視爲錯誤。 –