I get an infinite loop when I input a char(letter) in grade1, I want to know how do I not infinite loop when I input a char(letter)
Code:
#include<stdio.h> //important since printf
#include<conio.h> //impportan since clrscr()
main()
{
clrscr();
int G1,G2,G3;
float average,total;
char a;
printf("\nInput Grade1 out of 100:");
scanf("%d",&G1);
if (G1 > 100)
{
do
{
printf("Grade1 is > than 100, Please re-enter:");
scanf("%d",&G1);
}
while(G1 > 100);
}
if (G1 = a)
{
printf("Inputed Grade is char not a number, Please re-enter:");
scanf("%d",&G1);
}
printf("\nInput Grade2 out of 100:");
scanf("%d",&G2);
if (G2 > 100)
{
do
{
printf("Grade2 is > than 100, Please re-enter:");
scanf("%d",&G2);
}
while(G2 > 100);
}
printf("\nInput Grade3 out of 100:");
scanf("%d",&G3);
if (G3 > 100)
{
do
{
printf("Grade1 is > than 100, Please re-enter:");
scanf("%d",&G3);
}
while(G3 > 100);
}
total = G1+G2+G3;
printf("\nYour total grade is:""%f",total);
average = total/300;
printf("\n\naverage is:""%f",average);
getch();
}