# Error window o _ o'

• 09-23-2008
Regonics
Error window o _ o'
I have just started programming and i made a program that'll give me all the factors of the number i input

the code is the following
Code:

```#include <iostream> using namespace std; int main () {  int x,y,z;     cout << "Enter a number";     cin  >> x;     cout << x << " is divisible by " << x << ",";     z=x;      for (z=z;z>0;z-1)       {      z=z-1;           if ((x%z)==0)           {           cout << z << ",";           }       }          return 0; }```
It compiled fine and it the factors showed up but after i run the program a window pops up saying
(Factors.exe has encountered a problem and needs to close. We are sorry for the inconvenience.) (The WXP error window)

what did i do wrong with my code?
• 09-23-2008
Dino
You coded this:
Code:

```for (z=z;z>0;z-1)       {      z=z-1;```
and you should have coded this:
Code:

```for (z=z;z>0;z-=1)       {```
• 09-24-2008
matsp
Quote:

Originally Posted by Dino
...you should have coded this:
Code:

```for (z=z;z>0;z-=1)       {```

Or even:
Code:

```for (z=x-1;z>0;z--) ...```
.
and remove the z=x in the line above (doing "z=z" is pointless, so could be omitted, but since you really want z=x-1, that's what you should have there!)

The reason your application "stops" is that it tries to divide by zero, because the z=z-1 is done INSIDE the loop, rather than at the end of the loop.

Also, the variable y is not being used.

--
Mats
• 09-24-2008
Elysia
What IDE / editor do you use, if you don't mind me asking?
• 09-24-2008
Regonics
yeah, i just started so i dont know how to indent and such, i use Dev C++.
thanks for the help
• 09-24-2008
Will Hemsworth
> i use Dev C++.
When I used Dev C++, I noticed it had terrible indentation problems, thats when I changed to MSVS 2005, and its just takes away so many problems :cool:
• 09-24-2008
laserlight
Quote:

When I used Dev C++, I noticed it had terrible indentation problems
By default. Once you turn out the smart tab thing, the indentation is fine, at least from what I remember.
• 09-24-2008
Will Hemsworth
Quote:

By default. Once you turn out the smart tab thing, the indentation is fine, at least from what I remember.
Perhaps I just wasn't doing it right :p, but I was playing with the settings for quite a long time, and could never quite get it how I wanted.
• 09-24-2008
scwizzo
If you want a good free compiler (that doesn't have indenting issues) codeblocks is pretty good.
• 09-24-2008
laserlight
Quote:

If you want a good free compiler (that doesn't have indenting issues) codeblocks is pretty good.
Code Blocks is a pretty bad compiler, though it is fine as an IDE.
• 09-24-2008
matsp
Quote:

Originally Posted by laserlight
Code Blocks is a pretty bad compiler, though it is fine as an IDE.

What Laserlight is trying to say is that you are calling the IDE (which is a layer on top of/around the compiler) a compiler, which it isn't. It uses a very good compiler, gcc, but Code::Blocks is not a compiler in itself [as far as I know, not even in the slightest].

--
Mats