/* 
* Code Snippets for this week
* Small programs to show bits of C and bits of C. 
* >> I've tried to put * at the start of all the comment lines. 
*/

/* FOR Loop example 
*  NOTE: Use a for loop when you know how many time your going to loop in advance. 
*
*/
#include <stdio.h>

void main()
{
    float mark, average, total=0.0f;
    int count;
    const int MAX_NUMBERS = 10;
    
    /*   v initalise   v test           v update  */
    for (count=0; count < MAX_NUMBERS; count=count+1)
    {
         printf("\nEnter a mark :");
         scanf("%f",&mark);
         total = total + mark;
    }
     
    average = total / MAX_NUMBERS;
    
    printf("\nThe average mark is %f\n" ,average);
}

/* WHILE Loop example 
*  NOTE: Use a for while when you don't know how many time your 
*  going to loop in advance. 
*  
*  The example below uses a read ahead structure, 
*  its important to ensure with a while loop that something 
*  updates the variable in the while(..) each time to avoid 
*  infinate loops (crashes). 
*/
#include <stdio.h>

void main()
{
    float mark, average, total=0.0f;
    int count;
    const int MAX_NUMBERS = 10;
    count=0;

    printf("\nEnter a mark (negative to end input) :");
    scanf("%f",&mark);

    /*          v test - for operators see last week */
    while((count < MAX_NUMBERS) && (mark > 0.0f))
    {
         total = total + mark;
         count=count+1

         printf("\nEnter a mark (negative to end input):");
         scanf("%f",&mark);
    }
     
    average = total / MAX_NUMBERS;
    
    printf("\nThe average mark is %f\n" ,average);
}
