I got stumped can someone please help ?
I’m working on this home work assignment and can’t get past this point.

Here is how far I’ve got:

#include <iostream>
#include <iomanip>
 
using namespace std;
 
using std::cout;
using std::cin;
using std::endl;
 
int main()
{
 
int numbers,to,Enter,odd,even;
int integer,positive,a;
 
 
 
 
cout << " Enter a positive integer(0 to quit):";//0
 
cout << " Enter a positive integer(0 to quit):";//0
cin >> integer >>;
cout << "The total of the odd numbers entered is:";//0
cout << "The total of the even numbers entered is:";//0
 
 
cin >> Enter a positive integer(0 to quit):1;
cout << " 1 is odd";
cin >> Enter a positive integer(0 to quit):2;
cout << " 2 is even";
cin >> Enter a positive integer(0 to quit):3;
cout << " 3 is odd";
cin >> Enter a positive integer(0 to quit):4;
cout << " 4 is even";
cin >> Enter a positive integer(0 to quit):0<< endl
 
 
return 0;
 
 
}

And there is an attachment of the assignment:

Attachments scan.jpg 324.43 KB
#include <iostream>

using namespace std;

//declare the variable's
int total;
int number_buffer = 1;

//create an function that check's the number, putt's out wther it's odd or even and adds it to the total variable
bool checker(int number)
{
    if(number == 0){return false;}
    if(number%2)
    {
        cout << number << " is odd" << endl;
    } else {
       cout << number << " is even" << endl;
    }
    total += number;
}

int main()
{
//request user input
 cin >> number_buffer;
//continue to ask input unill 0 is entered, iff 0 is entered does checker return's false, else true.
 while(checker(number_buffer)){cin >> number_buffer;}
//show the total
 cout << "Total: " << total;
 return 0;
}

This will get you an end in the right direction. You might want to check the basic syntax out again, you made some mistakes in that to.

Comments
spreading some rep (by andor)

Yes just follow Mr. Anonymusius's advice and keep some things in mind:

1. Avoid the use of global variables since its a bad programmign practice.

2. If you dont know pass by reference make the function return the updated total. That looks like a good programmign practice :)

3. Another operator which can be used for conditional checking is the ternary operator ?:

bool isEven = ((a % 2) == 0) ? true : false ;

Hope it helped, bye.

PS: 0 is an even number.

Yes just follow Mr. Anonymusius's advice and keep some things in mind:

Mr. Anonymusius, I like that :P

1. Avoid the use of global variables since its a bad programmign practice.

But in small programm's like this doesn't it really matter, but in large programm's is it an bad habbit.

3. Another operator which can be used for conditional checking is the ternary operator ?:

bool isEven = ((a % 2) == 0) ? true : false ;

Ternary, so that's how that thing is called. No need to overcomplicate it, There is an easy if(){} else {} replacement for beginners.

Ternary, so that's how that thing is called. No need to overcomplicate it, There is an easy if(){} else {} replacement for beginners.

Learing something new each day is what to takes to keep moving ahead in life. The OP propably doesnt need the overcomplicated peice of ?: ternary operator to solve his problem but having the knowledge that such a thing exists doesnt hurt either, does it ;)

But in small programm's like this doesn't it really matter, but in large programm's is it an bad habbit.

A bad habit is a bad habit, no matter what size the program is. Sure, it can be easier for a small program, but that doesn't change things. Same could be said for goto. ;)

This article has been dead for over six months. Start a new discussion instead.