# Thread: help would be appreciated(newbie at this)

1. ## help would be appreciated(newbie at this)

Heres the problem

Write a program that inouts a serie of integer and pass them one at a time to function even which use the remainder operator to determine if an integer is even. The function should be integer arguement and return 1 is the integer is even and 0 otherwise.

Heres what i come out with so far

Code:
#include <stdio.h>

int main()
{
int integer1;
int odd;
int even;
int remainder;

printf("Enter an integer\n");
scanf("%d", &integer1);

remainder = (integer1%2);

if (remainder == 0) {
printf("%d", integer1);
printf("1\n");
}
if (remainder != 0) {
printf("%d", integer1);
printf("0\n");
}

return 0;
}

2. Hope this helps in your quest. From the FAQ board http://cboard.cprogramming.com/showthread.php?t=31212

3. if anyone can correst my program by rewriting he whole program it would be helpful because i dont really get what to so to correct it.

Code:
if (remainder )
{
printf("You entered %d, it is odd.\n"
}
else
{
printf("You entered %d, it is even.\n"
"Here's yor 1.\n\n", integer1);
}
Are you supposed to print 1 if even, or return 1. There's a difference.

dinjas

Code:
int yourfunc( int value )
{
//test whether value is even or odd
...

if it's odd
return 0;
else
return 1;
}
So, just make a function like this, and call it from main with your integer1 .

dinjas

6. It can be done without an if statement.
Code:
Function(int Value)
{
Value %= 2;
return !Value;
}

7. im new at this too.. but did you forget to put your cast in the printf:

old code
Code:
printf("Enter an integer\n");
scanf("%d", &integer1);
new code
Code:
printf("Enter an integer\n", integer1);
scanf("%d", &integer1);
hehe, maybe

8. Originally Posted by Quantum1024
It can be done without an if statement.
good call, I didn't think of that.

Originally Posted by <3pi
im new at this too.. but did you forget to put your cast in the printf:
as mentioned in the other post, you don't need to do anything special with printf unless you're printing the value of a variable.
ex.
Code:
printf("this is a line without a variable\n");
will display
Code:
this is a line without a variable
and
Code:
int number = 1;
printf("this one prints the value of the variable \"number\"\n"
"number's value is %d\n", number);
will display
Code:
this one prints the value of the variable "number"
number's value is 1
dinjas

9. Originally Posted by joker209
if anyone can correst my program by rewriting he whole program it would be helpful because i dont really get what to so to correct it.
Are you kidding? You've been given enough hints. Here's another one.
Code:
#include <stdio.h>
OO(O0){return !(O0 & 1);}main(_OO,_00)
int*_00;{int _0O;char _O0[]="How many\
integers will you enter? \0is\0odd.\n\
\0even.\n\0Enter an integer: \0";for(
_00=&_0O,printf("%s",_O0),scanf("%d",
_00),_00=&_OO;_0O;printf("%s",_O0+51),
scanf("%d",_00),OO(*_00)?printf("%d %s\
%s",*_00,_O0+35,_O0+44):printf("%d %s \
%s",*_00,_O0+35,_O0+38),_0O--);return _0O;}
Good luck with that class.

10. from reading the problem more closely now and testing my program, none of the code in this thread enable someone to enter series of numbers(more than one) and reads them in one at a time and inputs those number out in order. returns a 1 if the 1st number is a even number and 0 if its a odd number, same for the other numbers.

because the problem saids

Write a program that inputs a SERIES OF INTEGERS and pass them one at a time to function even which use the remainder operator to determine if an integer is even. The function should be integer arguement and return 1 is the integer if even and 0 otherwise.

I dont get this sentence at all: pass them one at a time to function even

11. Run result should be something like this

Enter an integer
8 93 92
1 0 1
Press any key to continue

12. It's basically asking you to create a function called 'even' that returns a 0 if odd and 1 if even. So I would start by creating a function, I'm pretty sure there are enough hints in the thread to go about creating it, but since you still seem pretty confused:

Code:
int even(int input)
{
return (input % 2 == 0);
}
Now you should be worrying about how to get the actual series of integers, theres a number of ways of going about doing this - one of the simpler options is to ask the user how many integers that are expecting and then keep reading in integers and storing it in an array or something. Once you read in all the integers (and processed them using even()) simply just print the array out. I'm pretty sure there are more efficient ways though