I know this is just a simple problem. I am new cprogramming student and I would like to know what and how I can incorporate the "%" function.

Printable View

- 04-14-2002cprogstudentjust a question
I know this is just a simple problem. I am new cprogramming student and I would like to know what and how I can incorporate the "%" function.

- 04-14-2002golfinguy4
Make a program that finds all the even or odd numbers below a user-inputted number.

- 04-14-2002matheo917
"%" is a so called "modulo" or as in school so called "remainder"....

i.e.

5 % 2 = 1...........

when you modulo (divide) 5 by 2... you see that two 2's fits in it making 4 and the remainder is 1...... - 04-14-2002Dual-Catfish
One use is to test for an even number...

short int number = 5;

if (!(number % 2))

{

cout << "Even number!";

} else {

cout << "Odd number!";

} - 04-14-2002Quantrizi
for single line if (and maybe else) statements, you don't need the "{" and "}". Although, I could be wrong.

- 04-14-2002cprogstudent
Hey thx for the help that really cleared things up.