Hi, I need some help on the following problem:

An number of students have taken two exams, exam 1 and exam 2. (We don't know exactly how many) The marks obtained are to be typed into the program. (Using scanf() I presume)

The first two numbers typed in are the scores obtained by the first student. The next two numbers are scores for the second student and so on. Write a program that calculates and then print the average score for exam1 and for exam 2.

The scores entered must be within the 0-100 range. Otherwise the marks should be ignored.

Here is what I have so far and it looks very messy:

Code:

#include <stdio.h>
int main()
{
int e1, e2, sum1, sum2;
sum1 = 0;
sum2 = 0;
scanf("%d %d", e1, e2);
if (e1 >= 0)
if (e1 <= 100)
sum1 = sum1 + e1;
scanf("%d %d", e1, e2);}
else
if (e2 >= 0)
if (e2 <= 100)
sum2 = sum2 + e2;
scanf("%d %d", e1, e2);
else
scanf("%d %d", e1, e2);
else
if (e2 >= 0)
if (e2 <= 100)
sum2 = sum2 + e2;
scanf("%d %d", e1, e2);
else
scanf("%d %d", e1, e2);
else
scanf("%d %d", e1, e2);

I know that we must somehow use the 'while' command but I don't exactly know how. How do I even start this problem?