/* Fig. 3.10: fig03_10.c
Nick Vincent
Analysis of examination results */
#include <stdio.h>
int main()
{
/* initializing variables in declarations */
int passes = 0, failures = 0, student = 0, result =0;
/* process 10 students; counter-controlled loop */
while ( student <= 10 )
{
printf( "Enter result ( 1 = pass, 2 = fail ): " );
scanf( "%d", &result );
if ( result == 1 ) { /* if/else nested in while */
passes = (passes + 1);}
else
{ failures = (failures + 1);
student = (student + 1);
result = 0;}
}
printf( "Passed %d\n", passes );
printf( "Failed %d\n", failures );
if ( passes > 8 )
printf( "Raise tuition\n" );
getchar();
getchar();
return 0; /* successful termination */
}
I have written the code above from my book. I need some instruction in the right direction on how to implement the "struct stack" idea that makes the program do the same thing. I have no idea on where to start besides declaring the "struct stack;" Any information would be great.
And btw: You may recheck whether you made a typo in the else-clause of the if in line 23. The closing bracket is in line 26, hence the student is only increment for failures.
Bazzy: Yes, that is a description of a stack data structure. My question was a rather rhetorical shortcut for "What has the data structure of a stack to do with your program at hand and are you aware by yourself what you actually want to achive?"