### Cant use decimal values in a call function?

Im currently using C, and when i try to call functions with decimals it doesn't let me do so and just changed the numbers into some crazy big random value.

Calling the function
 ``12`` `````` //First value = X, Second Value = Y, Third Value = Width, Fourth Value = levels Mickey(0,0,0.25,5);``````

The function
(when i use debugging, when it calls itself again it spits out absurd numbers for x, y, and level and width becomes 0, HOWEVER if i use whole numbers when calling the function it works properly)
 ``123456789101112131415161718192021`` ``````void Mickey(x1 ,y1 ,width1 ,level) { float x, y, width; width=width1; x=x1; y=y1; if(level >= 1) { glBegin(GL_QUADS); // Draw A Quad glColor3f(0.25f,0.25f,0.25f); glVertex3f(x, y, 0.0f); // Top Left glVertex3f(x + width, y, 0.0f); // Top Right glVertex3f(x + width, y-width, 0.0f); // Bottom Right glVertex3f(x, y-width, 0.0f); // Bottom Left glEnd(); // Done Drawing The Quad Mickey(x - (0.5 * width), y + (0.5 * width), width, level--); //Left Ear Mickey(x + width , y + (0.5 * width), width, level--); //Right Ear } }``````

Here is the full code (Uploaded it because theres no hide/spoiler tags):
https://dl.dropboxusercontent.com/u/155858369/mickey.c

Objective:
Create something like this
http://puu.sh/9ox0J/3e1973d218.png
Last edited on
 ``123456789101112131415161718192021222324`` ``````// void Mickey(x1 ,y1 ,width1 ,level) void Mickey( float x , float y , float width , int level ) { /* float x, y, width; width=width1; x=x1; y=y1; */ if(level >= 1) { glBegin(GL_QUADS); // Draw A Quad glColor3f(0.25f,0.25f,0.25f); glVertex3f(x, y, 0.0f); // Top Left glVertex3f(x + width, y, 0.0f); // Top Right glVertex3f(x + width, y-width, 0.0f); // Bottom Right glVertex3f(x, y-width, 0.0f); // Bottom Left glEnd(); // Done Drawing The Quad Mickey(x - (0.5 * width), y + (0.5 * width), width, level--); //Left Ear Mickey(x + width , y + (0.5 * width), width, level--); //Right Ear } }``````

Consider using `double` as the default floating-point type.
Last edited on
You haven't specified a type in your function. C will assume that these are int if an error isn't thrown.

Change line 1 to:
`void Mickey( float x1, float y1, float width1, int level);`
 You haven't specified a type in your function. C will assume that these are int if an error isn't thrown. Change line 1 to: void Mickey( float x1, float y1, float width1, int level);

i've just tried it but it doesnt fix the problem (screenshot below of watches)
(it crashes aswell)
Last edited on
 Did you read JLBorges's post? Particularly lines 4 to 9?

Just tried changing it to JLBorge's and i get this error
http://puu.sh/9oxnw/73ed059793.png
Last edited on
It looks like you pass an uninitialized variable into Micky's 4th parameter. With the debugger, put a breakpoint at the initial call of that function and check the value of the variable going into the 4th parameter.
 It looks like you pass an uninitialized variable into Micky's 4th parameter. With the debugger, put a breakpoint at the initial call of that function and check the value of the variable going into the 4th parameter.

At the intial call of function the value of the variables are:
X = 0
Y = 0
width = 0 (should be 0.5)
level = 1071644672 (should be 5)

-edit-

fixed it
Last edited on
Topic archived. No new replies allowed.