(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;
}
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 :
1 2 3 4
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)