Beginner C/C++

Moderators: None (Apply to moderate this forum)
Number of threads: 5430
Number of posts: 16951

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
while loop problem Posted by express_1 on 16 Oct 2012 at 1:08 PM
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!



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.