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 


Is it possible to shorten this code?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Random spam
View previous topic :: View next topic  
Author Message
gogodr
I post too much
Reputation: 125

Joined: 19 Dec 2006
Posts: 2041

PostPosted: Fri Jun 15, 2012 11:27 am    Post subject: Reply with quote

Code:
int a = 0;
for (int i=1;i<=10;i++){
a= i*100000000;
h = 9
if (l < 1000000000-a){
h = 9-i;
}
}


I think
Back to top
View user's profile Send private message MSN Messenger
gogodr
I post too much
Reputation: 125

Joined: 19 Dec 2006
Posts: 2041

PostPosted: Fri Jun 15, 2012 12:02 pm    Post subject: Reply with quote

oh yeah sorry.. the h=9 goes outside of the for loop

Code:

int a = 0;
h = 9
for (int i=1;i<=10;i++){
a= i*100000000;
if (l < 1000000000-a){
h = 9-i;
}
}



I just noticed... why dont you just use integer division?

its

if l is an integer

h = l/100000000

if it is not still do the division and then use the floor function.

your new code is:

Code:
h = l/100000000
Back to top
View user's profile Send private message MSN Messenger
gogodr
I post too much
Reputation: 125

Joined: 19 Dec 2006
Posts: 2041

PostPosted: Fri Jun 15, 2012 1:02 pm    Post subject: Reply with quote

the loop will work because outside of the conditions it sets h = 9
if inside the loop the condition is not met (( which is the same as else ))
h is not touched and still 9
but yeah dividing was the best solution.
Back to top
View user's profile Send private message MSN Messenger
Aniblaze
Grandmaster Cheater Supreme
Reputation: 138

Joined: 23 Apr 2006
Posts: 1757
Location: The Netherlands

PostPosted: Fri Jun 15, 2012 1:06 pm    Post subject: Reply with quote

Shrooms wrote:
gogodr wrote:
oh yeah sorry.. the h=9 goes outside of the for loop

Code:

int a = 0;
h = 9
for (int i=1;i<=10;i++){
a= i*100000000;
if (l < 1000000000-a){
h = 9-i;
}
}



I just noticed... why dont you just use integer division?

its

if l is an integer

h = l/100000000

if it is not still do the division and then use the floor function.

your new code is:

Code:
h = l/100000000


my friend on msn stated your code will not work if l is bigger than 900000000

I am now using
Code:

h=l/100000000;
if (h>9) {h=9;}

h = (h>9) ? 9 : h;

If the if-statement bothers you, you can replace it with the ternary operator.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Random spam 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