|
-
May 7th, 2011, 11:48 AM
#16
Re: need help please
Last edited by sadam; May 8th, 2011 at 12:18 PM.
-
May 7th, 2011, 12:28 PM
#17
Re: need help please
Most bugs dont cause the compiler to spit out an error. Most occur during runtime. For this you need to attach the debugger and step through your code watching the variables closely as i have already told you. You need to know what to expect, so as to see when something went wrong. When you find variables that hold values that are unexpected, if you are singlestepping your code you will see exactly where it happens and so be able to start working on solving the errors.
In future as you write each function, test it to ensure what you think is happening is actually what is happening.
Why cant you debug your code? What compiler and debugger and IDE are you using? Look in the docs for it to see how to work the debugger. Its time for you to learn.
Get Microsoft Visual C++ Express here or CodeBlocks here.
Get STLFilt here to radically improve error messages when using the STL.
Get these two can't live without C++ libraries, BOOST here and Loki here.
Check your code with the Comeau Compiler and FlexeLint for standards compliance and some subtle errors.
Always use [code] code tags [/code] to make code legible and preserve indentation.
Do not ask for help writing destructive software such as viruses, gamehacks, keyloggers and the suchlike.
-
May 7th, 2011, 12:35 PM
#18
Re: need help please
Last edited by sadam; May 8th, 2011 at 12:19 PM.
-
May 7th, 2011, 12:50 PM
#19
Re: need help please
Nope. Not wierd at all. Learn to use your debugger. Use your debugger.
Watch this.
Get Microsoft Visual C++ Express here or CodeBlocks here.
Get STLFilt here to radically improve error messages when using the STL.
Get these two can't live without C++ libraries, BOOST here and Loki here.
Check your code with the Comeau Compiler and FlexeLint for standards compliance and some subtle errors.
Always use [code] code tags [/code] to make code legible and preserve indentation.
Do not ask for help writing destructive software such as viruses, gamehacks, keyloggers and the suchlike.
-
May 7th, 2011, 12:56 PM
#20
Re: need help please
Last edited by sadam; May 8th, 2011 at 12:19 PM.
-
May 7th, 2011, 06:10 PM
#21
Re: need help please
 Originally Posted by sadam
i can't debug my own code because the compiler doesn't post me any error!!
the error that i have - and as i can see nobody knows how to solve it- is that when i try to run the program, it stops working
Everyone who has responded to you can solve the issue. The problem is can you solve it? That requires you to just sit down and learn how to debug your program using the debugger that comes with your compiler.
You didn't do that -- the only thing you did was write a big program, tried to run it, and want us to fix it without any effort on your part to see what is wrong.
Even if you didn't have a debugger, where are the cout statements to help you to know what the values of variables are, what lines of code you're executing, etc.? This is the harder way to debug, but at least it's something, but you didn't even do that.
Regards,
Paul McKenzie
-
May 7th, 2011, 06:16 PM
#22
Re: need help please
 Originally Posted by sadam
i am using the codeblocks as you told me the previous time, it's weird for a program to have no errors and while running it this stops working, isn't it?
Code:
#include <iostream>
int main()
{
double x = 1.0;
double y = x / (x - 1.0);
std::cout << y;
}
This program compiles OK. What do you think happens when y is computed (i.e. a divide by zero happens)? Will the program get to the cout statement?
Code:
#include <iostream>
int main()
{
char *p = 0;
*p = 'x';
std::cout << p;
}
This program compiles fine. What do you think happens when you assign a value to a NULL address?
Just because a program compiles doesn't mean when you run it, everything is OK. Is that what you were expecting, that all programs "work", and there is no need to debug them?
Regards,
Paul McKenzie
-
May 7th, 2011, 07:16 PM
#23
Re: need help please
Last edited by sadam; May 8th, 2011 at 12:20 PM.
-
May 7th, 2011, 08:40 PM
#24
Re: need help please
Last edited by sadam; May 8th, 2011 at 12:20 PM.
-
May 7th, 2011, 10:49 PM
#25
Re: need help please
One, we wouldn't be able to just look at the code and tell what is wrong. We would need to debug it. An IDE will have an option to debug your program. You can set a breakpoint at a line. From there, you will have options to step through the code. When you get to a function, you can either step over that function or step into that function. Really, if you are going to program in C++, using the debugger is a must.
-
May 8th, 2011, 06:04 AM
#26
Re: need help please
Last edited by sadam; May 8th, 2011 at 12:21 PM.
-
May 8th, 2011, 11:40 AM
#27
Re: need help please
 Originally Posted by sadam
after being familiar with the debugger i have managed to use it and it posts me this results:
Those are not warnings from the debugger. Those are warnings from the compiler when you are building your program.
The debugger is used when your program has been built, and you are running your program, and you are seeing how your program runs by inspecting the value of variables, setting breakpoints, etc.
Regards,
Paul McKenzie
-
May 9th, 2011, 10:04 AM
#28
Re: need help please
 Originally Posted by sadam
aaaaaaa
Someone's thrown their toys out the pram
"It doesn't matter how beautiful your theory is, it doesn't matter how smart you are. If it doesn't agree with experiment, it's wrong."
Richard P. Feynman
-
May 9th, 2011, 12:19 PM
#29
Re: need help please
I thought it was to keep the teacher and classmates out of it.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|