My program is due today and I'm stuck at work trying to figure this out I have been using the web to get this done.
Instructions: Write a program that adds the positive odd numbers you enter from the keyboard while ignoring the even numbers, and stops when a negative number or zero are entered.
Display the sum of the accepted odd numbers.
This is what I have.
#include <iostream>
using namespace std;
int main(void)
{
int N = 0;
int sum = 0;
cout << "Enter a whole number:" << endl;
cin >> N;
if ( N < 0 )
{
cout << "The number was not within the proper range." << endl;
return 1;
}
for( int i = 1; i <= N; i = i + 2){
sum = sum + i;
}
cout << "The total sum is: " << sum << endl;
return 0;
}
I'm just not cofident at all about this!