hallo guys!
i have been studying C programming. i was typing some codes and trying to find alternative solutions about the given problem.
first of all the below code is not mine and it made me really confused.
first please check the code. and i will ask my question after.
Code:
#include <stdio.h>
int main(void){
int grade;
unsigned int acount=0;
unsigned int bcount=0;
unsigned int ccount=0;
unsigned int dcount=0;
unsigned int fcount=0;
puts("enter the letter grades");
puts("enter the E0F character to end input");
while((grade=getchar()) != E0F){
switch(grade){
case 'A':
case 'a':
++acount;
break;
case 'b':
case 'B':
++bcount;
break;
case 'C':
case 'c':
++ccount;
break;
case 'D':
case 'd':
++dcount;
break;
case 'F':
case 'f':
++fcount;
break;
default:
printf("%s","incorrect letter grade entered,enter new one");
break;
} //end switch
}// end while
puts( "\nTotals for each letter grade are:" );
printf( "A: %u\n", aCount ); // display number of A grades
printf( "B: %u\n", bCount ); // display number of B grades
printf( "C: %u\n", cCount ); // display number of C grades
printf( "D: %u\n", dCount ); // display number of D grades
printf( "F: %u\n", fCount ); // display number of F grade
}//end main
now you understand the code. there is code for counting letter grades. my question is this
why should i need to use E0F character to stop while loop ? i mean, why i can not use simply -1 to exit this code ?
and in order to execute E0F , i should press ctrl+z, otherwise it won't work. how can i turn off this feature.
and about while and getchar, i understand , i should get an input from user, but without defining any char character how does it works ?
i mean the right code according to me should be this
char x; // i defiend a character
then
while(getchar() .... etc)
did i use int grade as a character in this form ?
thank you for your help and answers. and sorry i am a new bee