You are using a version without Ads of this website. Please, consider donating:

### even numbers

(Even Numbers) Write a program that inputs a series of integers and passes them one at a
time to function isEven, which uses the modulus operator to determine whether an integer is even.
The function should take an integer argument and return true if the integer is even and false otherwisw(how to program c++_deitel & deitel)

We don't know that user how many numbers have.what we can do?

I wrote this program but I know that it hase many problem!!!!!!!!!
(I shoudn't use 'string')

#include "stdafx.h"
#include<iostream>
using namespace std;

bool even (int);

int _tmain(int argc, _TCHAR* argv[])
{
int number;
cout<<"Enter the numbers.";
while(true)
{

cin>>number;
even (number);

}

bool even (int number)
{
int x;
x=number%2;
if(x=0)
return true;
else
return false;
}

this will work

 ``1234567891011121314151617181920212223`` ``````#include void even(int number); void even(int number) { if(number%2 == 0) {std::cout << number << " is even" << std::endl;} else {std::cout << number << " is odd" << std::endl;} } int main() { int number; while(true) { std::cout<<"Enter a number" << std::endl; std::cin >> number; even(number); } }``````
thank you so much.
but the program should "return" true or false

I don't undrstand exactly that when question ask us "return"; what does cout???!!!!
cout prints an output in your console

if it has to be bool, use this:

 ``1234567891011121314151617181920212223242526`` ``````#include bool even(int number); bool even(int number) { if(number%2 == 0) {return true;} else {return false;} } int main() { int number; while(true) { std::cout<<"Enter a number" << std::endl; std::cin >> number; if(even(number)) {std::cout << number << " is even" << std::endl;} else {std::cout << number << " is odd" << std::endl;} } }``````
Last edited on
thank you so much.
Excuse me!!!!
can you explain for me that "if(evan(number))" what does mean????
even(number) returns true, if the number is even and false if the number is odd

so basically if(even(number)) checks if(true) or if(false)

to explain this a bit more :
 ``1234`` ``````if(statement) { //commands }``````

commands get executed, if the statement is true. so you could write stuff like
if(1 == odd), if(100 > 10), if(-5 < 0),... all these statements are true
but to cut a long story short you can simply write if(true)
Last edited on
thank you again.
Topic archived. No new replies allowed.

You are using a version without Ads of this website. Please, consider donating: