how to make a program using while loop and the output is:

Status
Not open for further replies.

bob hays

Honorable
Nov 21, 2012
69
0
10,610
if this is in c or java (few differences, same idea)

int x, sum;

while(i<3)
{
printf("Enter a grade: ");
scanf(%d, x);
sum+=x;
i++;
}

printf("Average: %d", sum/3);



replace %d with %lf and initialize variables as a double if you aren't using whole number grades or don't want a whole number rounded average. Also if the number of grades isn't always 3, add another variable to count that and use total++; to make a total grades counter.
 
Status
Not open for further replies.