Archived

This topic is now archived and is closed to further replies.

jnr

divide error

Recommended Posts

I have a C++ program that "causes a divide error" Can you tell me common causes for a divide error There is no division operator in my program, so I''m quite sure n / 0 never happens. Any suggestions? Thanks

Share this post


Link to post
Share on other sites
1) run it in the debugger
2) look at the stack trace when the error happens
3) set a breakpoint on the line before the bad function
4) run the program again
5) inspect values, step through program, figure out what goes wrong

Btw: The "%" operator is often implemented in terms of "/", so "% 0" would also cause a divide error. That''s why bit masking ("&") is usually faster than modulo ("%").

Share this post


Link to post
Share on other sites
I''m having trouble with the debugger in Dev-C++

I checked "generate debugging information" in Tools, Compiler Options, Settings, Linker then did rebuild all

When I choose debug from the debug menu the console comes up but doesn''t seem to do anything more than sit there. I tried pushing the buttons on the debug tab and nothing seems to happen.

the output GDB thing whatever that is says a few "prompt" "pre-prompt" "post-prompt" and there''s a "program exited with error.."

What''s my problem?

Thanks

Share this post


Link to post
Share on other sites
Have you tried setting a Breakpoint at the function header, stepping through the code and using watches to see what values the variables hold as the function progresses?

Share this post


Link to post
Share on other sites
alright I got a little further

I see how to step through the code now, but nothing ever appears in the console window. Is that how it''s supposed to be? How do I input, that is, reply to a cin comand?

Thanks

Share this post


Link to post
Share on other sites
You have to actually step through the code. for that you use F8 or F7 i can''t remember. If you select a variable and press Ctrl+F5 you''ll mark that variable in a watch window so you can see what values it/they contain

Share this post


Link to post
Share on other sites