៧. បញ្ចូល និងបង្ហាញចំនាត់ថ្នាក់សិស្ស(switch, case)¶
លំហាត់ទី៧¶
- សរសេរកម្មវិធី បញ្ចូលពិន្ទុសិស្ស និងបង្ហាញលទ្ធផលលើscreen។
- ខ្សោយណាស់ ពី ០ទៅ ៣
- ខ្សោយ ៤
- មធ្យម ពី៥ ទៅ៦
- បង្គួរ ពី ៧ទៅ ៨
- ពូកែ ពី ៩ទៅ ១០
- វាយខុស បើដំលៃខុសពីនឹង។
- ផ្ដល់ជម្រើស វាយឡើងវិញ ឬបញ្ឈប់។
Source¶
#include <stdio.h>
int main(){
int score;
tt: printf("Enter student's data\n");
printf("Score: "); scanf("%d", &score);
switch(score){
case 0:
case 1:
case 2:
case 3: printf("Very poor");
break;
case 4: printf("Poor");
break;
case 5:
case 6: printf("Fair");
break;
case 7:
case 8: printf("Good");
break;
case 9:
case 10: printf("Very good");
break;
default: printf("Number not valid!!!");
}
printf("\nTo be continue, type 1 /stop, type 0: ");
scanf("%d", &score);
if(score == 1) goto tt;
else printf("\nBye!\n");
return 0;
}
Output¶
Enter student's data
Score: 5
Fair
To be continue, type 1 /stop, type 0: 1
Enter student's data
Score: 4
Poor
To be continue, type 1 /stop, type 0: 1
Enter student's data
Score: 8
Good
To be continue, type 1 /stop, type 0: 1
Enter student's data
Score: 9
Very good
To be continue, type 1 /stop, type 0: 0
Bye!