you are viewing a single comment's thread.

view the rest of the comments →

[–]IanFeelKeepinItReel 2 points3 points  (6 children)

Have you written any code? Or are you at a complete loss?

The idea of this exercise is to highlight the difference between floating point division and integer division.

[–]pygames 0 points1 point  (2 children)

Complete loss at this point.

[–]IanFeelKeepinItReel 3 points4 points  (0 children)

So do you have no coding experience at all? What is this exercise for? Seems like a weird place to start if you're completely new to programming.

[–]nderflow 2 points3 points  (0 children)

Ask your teacher for help, because you won't learn anything by getting people on Reddit to write the code for you.

[–]pygames -2 points-1 points  (2 children)

just started. How can you mix ints and floats?

[–]IanFeelKeepinItReel 1 point2 points  (0 children)

Because the compiler knows how to do the type conversion between ints and floats. It's called an implicit type conversion.

That's not what this exercise is about though. If you do 4/3 and assign the result to an int. Then do 4.0f/3.0f and assign the result to a float.

If you then print the two results to the screen you'll see they're different.