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
9
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.
Thread starter Similar threads Forum Replies Date
D Apps General Discussion 1
BlueMoon1890 Apps General Discussion 0
Neon The (Anthro) Umbreon Apps General Discussion 1
K Apps General Discussion 2
T Apps General Discussion 10
M Apps General Discussion 2
R Apps General Discussion 3
S Apps General Discussion 2
N Apps General Discussion 1
P Apps General Discussion 4
A Apps General Discussion 8
I Apps General Discussion 2
arpitsri Apps General Discussion 2
S Apps General Discussion 1
shattered space Apps General Discussion 6
U Apps General Discussion 9
D Apps General Discussion 1
jefe323 Apps General Discussion 10
B Apps General Discussion 4
L Apps General Discussion 14

ASK THE COMMUNITY