i must be missing something, whats wrong with this?
float controlFrameRate = 1/60;
It should be assigning something like 0.0166666667 but its coming out 0.00000 etc. is visual studio just lying to me?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
That is because
1/60is an integer, which is 0 because integer division truncates. This is used to initialize the float, giving0.You can fix it by making the RHS expression a float in the first place:of
In C++, literals such as
1,42etc. areint,1.0,3.1416aredouble, and thefin1.0fmakes the literal afloat. Note that thefcould have been omitted in the examples above. However, assigning a double to a float could be problematic if the double’s value goes beyond the range of a float.