Please Help C++

Posted by SteelDog37 on Tue 08 Nov 2011 12:01 AM — 3 posts, 15,054 views.

#0
Here is the question?
I am doing this program that ask the user to enter 20 numbers. The program adds only the positive numbers. It must skip all negative numbers. And output the sum of the positive numbers found.
Here is an example written algorithm:
Sample input/output:
Enter a list of 20 numbers:
2 3 1 -6 10 2 6 5 9 -10 9 2 -4 3 1 2 -6 7 3 2
The sum of the positive numbers is: 67
So far I have this as my input:

#include <iostream>

using namespace std;

const int N = 20;

int main()
{
int i, num, even = 0;
int stop;
for (int i = 0; i < 20; i++){
cout << "Enter a list of 20 numbers " <<endl;;
cin >> num;
cout << endl;
{

{
even = even + num;
}
}
cout << "The sum of the even integers is: " << even << endl;
}
system("PAUSE");
return EXIT_SUCCESS;
}

But every time I run this program I get this,
The sum of even integers is: 29
Enter list of 20 numbers

The sum of even integers is: 32
Enter the list of numbers

And so on after about the eight one then it says Press any key to continue. Not sure what I am missing or if I have to much of something.
USA Global Moderator #1
I really don't think this forum was created to give you a place to post all of your homework assignments for other people to help with.
#2
are you restricting the math login anywhere to not count negative numbers?

like:


int main()
 {
 int i, num, even = 0;
 int stop;
 for (int i = 0; i < 20; i++){
 cout << "Enter a list of 20 numbers " <<endl;;
 cin >> num;
 cout << endl;
 {
 
{
 if(num > 0) even = even + num;
 }
 }
 cout << "The sum of the even integers is: " << even << endl;
 }
 system("PAUSE");
 return EXIT_SUCCESS;
 }
 



i don't see anything that will "skip" negative integers.