Skip to main content
GameDev.net gamedev.net
🔒 Locked

Division by zero

Started by MrPickle Feb 26, 2009 at 10:15 AM 3 replies 650+ views
Original Post
MrPickle
MrPickle
My program keeps on crashing saying I'm dividing by zero even though I have a check to make sure that I'm not dividing by zero, why?
DWORD last_time = 0, elapsed = 0;
int FPS = 0;

//

while(running == true)
{
	elapsed = GetTickCount() - last_time;
	if(elapsed == 0) elapsed == 1;
	last_time = GetTickCount();

	//

	FPS = 1000/elapsed;
}



Here to learn :)
shwasasin
shwasasin
Quote:
Original post by MrPickle
My program keeps on crashing saying I'm dividing by zero even though I have a check to make sure that I'm not dividing by zero, why?

*** Source Snippet Removed ***


You're using the equals operator for setting elapsed instead of the assignment operator.

Your Code:
elapsed == 1;

Right Code:
elapsed = 1;
MrPickle
MrPickle
Quote:
Original post by shwasasin
Quote:
Original post by MrPickle
My program keeps on crashing saying I'm dividing by zero even though I have a check to make sure that I'm not dividing by zero, why?

*** Source Snippet Removed ***


You're using the equals operator for setting elapsed instead of the assignment operator.

Your Code:
elapsed == 1;

Right Code:
elapsed = 1;


Omg, I feel so stupid right now >.<

Thank you.
Here to learn :)
DevFred
DevFred
int x = 0;if (x == 0) x == 1;

When I compile that, I get "warning: statement has no effect". Crank up your warning levels!
daviangel
daviangel
Quote:
Original post by DevFred
int x = 0;if (x == 0) x == 1;

When I compile that, I get "warning: statement has no effect". Crank up your warning levels!

Yup do yourself a favor and let the compiler do more of the work for you [wink]
[size="2"]Don't talk about writing games, don't write design docs, don't spend your time on web boards. Sit in your house write 20 games when you complete them you will either want to do it the rest of your life or not * Andre Lamothe

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.