Quantcast
Channel: Programmers Heaven Forums RSS Feed
Viewing all articles
Browse latest Browse all 2703

while loop problem

$
0
0
This problem is from a previous assignment that I only recieved partial credit on, and I want to know where I went wrong.

The task is, by using a while loop, to take 4 integers and sum up only those that are greater or equal to ten.

Here's what I had so far:

#include <stdio.h>

int main()
{
int counter;
int grade;
int total;

total = 0;
counter = 1;

while( counter <= 4 ) {
printf( "Enter an integer:\n" );
scanf( "%d", &grade );
counter++;


if ( grade >= 10 ) {

total = total + grade;
}
else {
total = total;
}



printf( "The total is %d\n", total );
}


return 0;

}

Any help would be greatly appreciated! Thank you!

Viewing all articles
Browse latest Browse all 2703

Trending Articles