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.
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.