hi guys need some help, my program seems to loop forever when any non-integer value is entered in an integer input
heres my code
Code:
/********************************
* *
* Grade Calculator *
* *
*********************************
* *
* James Daniel Archer *
* *
* 15th December 2004 *
* *
*********************************
* *
*Input number of students, input*
*each students mark, calculate *
*each students grade, output *
*number of students, the average*
*grade for all students, & the *
*number of students achieving *
*each grade. *
* *
*********************************
* *
*Running the program:- *
* -Double click on the EXE *
* file to run the program. *
* *
*********************************
* *
*References:- *
* -N/A *
* *
*********************************
* *
*Restrictions:- *
* -The program will not output*
* a list of all students and *
* their achieving grade. *
* *
*********************************
* *
*Error handling:- *
* -The program will ask the *
* user to re-input data if an*
* error is detected. The *
* system will continue to ask*
* the user to re-input the *
* data until an acceptable *
* value is entered. *
* *
*********************************
* *
*See structure chart for more *
*information. *
* *
********************************/
/* Header Files */
#include <stdio.h>
#include <dos.h>
/* Functions */
void initialise(void);
void input(void);
void process(void);
void output(void);
/* Functions NOT Included On Stucture Chart
These Functions Are Used For Program Presentation */
void intro(void);
void clear(void);
void load(void);
/* Global Variables */
int students, mark, count, failcount, passcount, meritcount, distinctioncount, total;
float average;
char fname[16], sname[16];
main()
{ /* Program Start */
system("cls"); /* Clear Screen To Remove Data On Screen From Previous Programs */
initialise(); /* Function Calls */
intro();
input();
load();
clear();
process();
load();
clear();
output();
clear();
} /* Program End */
void initialise(void)
{ /* Initialise Function Start */
students=0; /* Global Numeric Variables Initialised To 0 */
mark=0;
count=0;
failcount=0;
passcount=0;
meritcount=0;
distinctioncount=0;
average=0;
} /* Initialise Function End */
void input(void)
{ /* Input Function Start */
printf("Please Input The Number of Students You Wish To Grade");
printf(" \n");
printf(" \n");
scanf("%d",&students); /* Data Input 1 (Number of Students) */
printf(" \n");
printf(" \n");
while((students <1) || (students >60)) /* Validation Loop 1 (Number of Students Within Rage 1 - 60) */
{ /* Validation Loop 1 Start */
printf("Error 001 - Number Out of Range! \a"); /* Error Message With System Beep */
printf(" \n");
printf(" \n");
printf("Please Input The Number of Students You Wish To Grade");
printf(" \n");
printf(" \n");
scanf("%d",&students); /* Data Input 1 (Number of Students) */
printf(" \n");
printf(" \n");
} /* Validation Loop 2 End */
} /* Input Function End */
void process(void)
{ /* Process Function Start */
for(count=1; count<=students; count++) /* Loop 1 (Repeat The Following Code For Each Student) */
{ /* Loop 1 Start */
printf("Please Input Students First Name");
printf(" \n");
printf(" \n");
scanf("%s",fname); /* Data Input 2 (Students First Name) */
printf(" \n");
printf(" \n");
printf("Please Input Students Surname");
printf(" \n");
printf(" \n");
scanf("%s",sname); /* Data Input 3 (Students Surname) */
printf(" \n");
printf(" \n");
printf("Please Input Students Mark");
printf(" \n");
printf(" \n");
scanf("%d",&mark); /* Data Input 4 (Students Mark) */
printf(" \n");
printf(" \n");
while((mark <0)||(mark >100)) /* Validation Loop 2 (Students Mark Within Range 0 - 100) */
{ /* Validation Loop 2 Start */
printf("Error 001 - Number Out of Range! \a"); /* Error Message With System Beep */
printf(" \n");
printf(" \n");
printf("Please Input Students Mark");
printf(" \n");
printf(" \n");
scanf("%d",&mark); /* Data Input 4 (Students Mark) */
printf(" \n");
printf(" \n");
} /* Validation Loop 2 End */
printf("Clearing Screen, One Moment Please...");
sleep(1); /* Program Pause (1 Second) */
system("cls"); /* Clear Screen */
printf("Students Results");
printf(" \n");
printf(" \n");
printf("%s",fname); /* Data Output 1 (Students First Name) */
printf(" %s",sname); /* Data Output 2 (Students Surname) */
printf(" \n");
printf(" \n");
if(mark<40) /* IF Statement 1 (Fail Grade) */
{ /* IF Statement 1 Start */
printf("GRADE: FAIL");
failcount++; /* Increment The Fail Count */
} /* IF Statement 1 End */
else
if(mark<65) /* IF Statement 2 (Pass Grade) */
{ /* IF Statement 2 Start */
printf("GRADE: PASS");
passcount++; /* Increment The Pass Count */
} /* IF Statement 2 End */
else
if(mark<75) /* IF Statement 3 (Merit Grade) */
{ /* IF Statement 3 Start */
printf("GRADE: MERIT");
meritcount++; /* Increment The Merit Count */
} /* IF Statement 3 End */
else /* Final Else (Distinction Grade) */
{ /* Final Else Start */
printf("GRADE: DISTINCTION");
distinctioncount++; /* Increment The Distinction Count */
} /* Final Else End */
total=total+mark; /* Calculation To Determine The Total Value of All Marks */
printf(" \n");
printf(" \n");
printf("Press Any Key To Continue");
getch(); /* Wait For User To Press A Key */
system("cls");
} /* Loop 1 End */
} /* Process Function End */
void output(void)
{ /* Output Function Start */
average=total/students; /* Calculation To Determine The Average of All Marks */
printf("Number of Students: %d",students); /* Data Output 3 (Number of Students) */
printf(" \n");
printf(" \n");
printf("Average Mark: %.2f",average); /* Data Output 4 (Average Grade) */
printf(" \n");
printf(" \n");
printf("Number of Students Achieving The Following Grades");
printf(" \n");
printf(" \n");
printf("Fail: %d",failcount); /* Data Output 5 (Students Achieving Fail) */
printf(" \n");
printf("Pass: %d",passcount); /* Data Output 6 (Students Achieving Pass) */
printf(" \n");
printf("Merit: %d",meritcount); /* Data Output 7 (Students Achieving Merit) */
printf(" \n");
printf("Distinction: %d",distinctioncount); /* Data Output 8 (Students Achieving Distinction) */
printf(" \n");
printf(" \n");
printf(" \n");
printf("Press Any Key To Exit");
getch(); /* Wait For User To Press A Key */
} /* Output Function End */
void intro(void)
{ /* Intro Function Start */
printf("Archer Software Presents\n");
printf("Grade Calculator\n");
printf(" \n");
printf("One Moment Please...");
sleep(2); /* Program Pause (2 Seconds) */
printf(" \n");
printf(" \n");
} /* Intro Function End */
void clear(void)
{ /* Clear Function Start */
printf(" \n");
printf(" \n");
printf("Clearing Screen, One Moment Please...");
sleep(1); /* Program Pause (1 Second) */
system("cls");
} /* Clear Function End */
void load(void)
{ /* Load Function Start */
printf("Loading.");
sleep(1); /* Program Pause (1 Second) */
printf(".");
sleep(1); /* Program Pause (1 Second) */
printf(".");
sleep(1); /* Program Pause (1 Second) */
printf(".");
printf(" \n");
printf(" \n");
} /* Load Function End */
thnx