Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

while loop problem

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

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

total = 0;
counter = 1;

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


if ( grade >= 10 ) {

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



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


return 0;

}

Any help would be greatly appreciated! Thank you!
Sign In or Register to comment.