GP32 Division Problems / Remainder


ConsoleTom

Member
Joined
Dec 4, 2003
Messages
106
Age
48
Location
Germany
Website
Visit site
Hi !

I want to write a routine for choose values. Example: Values 0-32 in 4 columns. The only problem is, how to find the remainder and use it in if.

When i want to put 0-32 (33 Values since counted from 0) in 4 columns, each column needs 8.025 (it may be wrong, but its an example) lines. So i would like to make 9 lines out of it.

In a short sentence: if remainder of x/y != 0, add 1.

The solution i tried did not work:

nValuesPerCol = (nValues/nCols); /* how many entries per col */
if (nValues%nCols) nValuesPerCol++;

Any idea ? Perhaps datatype-problem ? Or what ?

Greetings

Tobias
 
I'm not 100% sure if i understand you completely, but am I right that you're looking for a method to get the remainder of a division?

You can do it in two ways:

either by using division and mod:

int quot=33/4 (will be 8)
int rem=33%4 (will be 1)
if (rem>0) quot++;

so basically very much what you did (can't figure out what's wrong yet)

Or:

use stdlib.h:

div_t div (int zaehler, int nenner)
I don't know the english words for that. ;)

like:

div_t foo;
foo=div(33, 4);
int quotient=foo.quot;
int remainder=foo.rem;

and then go on with the if-testing.

Hope that helps.
 
Back
Top