Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Stupid doubt about C (division)

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Unbr0ken
Advanced Cheater
Reputation: 2

Joined: 10 Aug 2011
Posts: 67

PostPosted: Thu Sep 06, 2012 2:58 pm    Post subject: Stupid doubt about C (division) Reply with quote

Why in C when I divide the following numbers: 230 / 114, returns 2.0000... ?

And when I divide them in the calculator, it shows some decimals... (2.01754386)

This code must work (I guess):

Code:
#include <stdio.h>

int main(void)
{
   printf("%f", (float)(230 / 114));
   getchar();
   return 0;
}


But no!... at least on Qt-Creator with GCC doesn't work.

Is there an explanation? for stupid that it be.
Back to top
View user's profile Send private message Send e-mail MSN Messenger
Dark Byte
Site Admin
Reputation: 471

Joined: 09 May 2003
Posts: 25860
Location: The netherlands

PostPosted: Thu Sep 06, 2012 3:06 pm    Post subject: Reply with quote

You need to think about the order

First the integer 230 is divided by the integer 114 (2)
Then that result is converted to a floating point (2.0)
And then printed to the screen


try this:
(float)230/(float)114

or this
230.0f/114.0f

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
Unbr0ken
Advanced Cheater
Reputation: 2

Joined: 10 Aug 2011
Posts: 67

PostPosted: Thu Sep 06, 2012 3:39 pm    Post subject: Reply with quote

What a shame!

Thanks Dark Byte!
Back to top
View user's profile Send private message Send e-mail MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites