|
From: Saundra S. <Sch...@ho...> - 2000-11-11 15:01:42
|
Hi, I've been having difficulty getting my switch statements to work =
properly. When I run the program no matter what I enter I get the =
default response. Please help. I've inculded a sample from my text. I =
need the switch statement to work for an assignment.
#include <stdlib.h>
int main()
{
int grade;
int aCount =3D 0, bCount =3D 0;
printf("Enter the letter grades.\n");
printf("Enter the -1 to end input.\n");
while( (grade =3D getchar()) !=3D -1)
{
switch(grade)
{
case 'a': case 'A':
++aCount;
break;
case 'b': case 'B':
++bCount;
break;
default:
printf("Incorrect letter grade entered.");
printf("Enter a new grade.\n");
break;
}
}
printf("%d\n", aCount);
printf("%d\n", bCount);
system("PAUSE");
return 0;
}
|