# Need Help quick reply plz

• 04-11-2002
playboy1620
Hi. Tomorrow is my programming exam, and today I have pulled out the past exam paper, and I took this question out from last semesters exam. I needed help for this question because I was very confused, anywayz, I made an effort to answer this question, anyone can correct me? The question is below in this post, and my answer will be below this post. The part that got me confused is when I reach to the statement “If the counter not equal to zero”. What will be the condition for while (?) ?????

----------------------------------------------------------------------------------------------

(Exam Question): Write a program that receives marks and gives the class averages with sentinel-controlled repetition. Use the following algorithms as your guide. (10 marks)

Initialize total to zero
Initialize counter to zero
Input the first mark
While the user has not yet entered the sentinel value
Add this mark into the running total
Add one to the mark counter
Input the next mark (possibly the sentinel)

If the counter is not equal to zero
Set the average to the total divided by the counter
Print the average
Else
Print “No marks were entered”

---------------------------------------------------------------------------------------------------

(My Answer): int total=0, counter=0, mark;

do{
printf("Plz enter a mark");
scanf("%d", &mark);

while (counter!=0){
++counter;
total+=mark;}

if (counter!=0)
average = total/counter;
else
printf("No marks entered");

}

printf("Average is %d", average);
• 04-11-2002
Drako

int total=0, counter=0, mark = 0, average;

do{
printf("Plz enter a mark");
scanf("%d", &mark);

counter++ ;
total+=mark;

} while (mark > 0) ;

if (counter!=0)
average = total/(counter-1);
else
printf("No marks entered");

printf("Average is %d", average);

}