Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ Programming
➜ General
➜ Please Help C++
It is now over 60 days since the last post. This thread is closed.
Refresh page
| Posted by
| SteelDog37
(4 posts) Bio
|
| Date
| Tue 08 Nov 2011 12:01 AM (UTC) |
| Message
| 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.
| | Top |
|
| Posted by
| Fiendish
USA (2,555 posts) Bio
Global Moderator |
| Date
| Reply #1 on Wed 09 Nov 2011 07:40 PM (UTC) |
| Message
| | 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. |
https://github.com/fiendish/aardwolfclientpackage | | Top |
|
| Posted by
| Daniel Spain
(15 posts) Bio
|
| Date
| Reply #2 on Sun 13 Nov 2011 09:56 AM (UTC) |
| Message
| 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.
| | Top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
14,354 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top