problem: Enter three subject names and three judgment messages in advance using an array of character pointers, enter the points, and then create a flow chart and source program for the program that displays the judgment for each subject. ・ If the score is not from 0 to 100, display "Input error", 60 or more as "Pass", and others as "Fail". -Use repeated statements when inputting and outputting points and judgments.
sample.c
#include <stdio.h>
#include <string.h>
int main(void)
{
int a=0,b=0,c=0;
int max = 100;
int min = 0;
char *key[3] = {"National language", "Math", "English"};
int number[3] = {a,b,c};
for (int i=0;i<3;i++{
printf("%s:",key[i]);
scanf("%d", &number[i]);
}
printf("***Judgment***\n");
for (int i = 0;i< 3;i++){
if(number[i] < min || number[i] > max){
printf("%s:Input error\n",key[1]);
}else if(number[i]>59){
printf( "%s:Pass\n",key[2]);
}else if (number[i] < 60){
printf( "%s:failure\n",key[3]);
}
}
return 0;
}
I had a hard time displaying it with `printf``` because the input of the subject was specified in the array. .. .. Also, I forgot how to assign ```i``` to the array in the iterative statement, so when I wrote three
`printf```, the execution result was unreasonable.
I learned how to declare an array of character pointers. I was able to relearn conditional branching.
If you are familiar with C language and can code more concisely based on this question, I would appreciate it if you could let me know.
Recommended Posts