# Looping Failed "Second Problem"

• 02-21-2013
loserone+_+
Looping Failed "Second Problem"
my looping code failed,
whats wrong with it i didnt figure it out,
here's my problem
Code:

```int main()           {   int x;   int y;   int n;   int m=0;   printf("First Number =");scanf("%d",&x);   printf("Divide Number =");scanf("%d",&y);   printf("Loop Number =");scanf("%d",&n);   while(m<n)  {   x+=y;   printf("%d,",x);                     }           }```
Thats for while loop,
here is with do while loop,
Code:

```int main()           {   int x;   int y;   int n;   int m=1;   printf("First Number =");scanf("%d",&x);   printf("Divide Number =");scanf("%d",&y);   printf("Loop Number =");scanf("%d",&n);   do{   x=x+y;   printf("%d,",x);     } while(m<n);           }```
okay, sorry if my code is "unreadable" like other guy said yesterday to me. This the best i can do to explain my problem.
Any ideas?
• 02-21-2013
whiteflags
If you can't be bothered to indent properly, have a program do it for you until you can.

Basically all your loops have the same problem. m < n is true forever, because neither variable changes.
• 02-21-2013
Zul56
you need to increase the value of m in the while loop so that it reach n; to end the loop. Using m+=1 at the end of the while loop would help.
• 02-21-2013
Cat
Code:

```would,  youreaD          a bookwhere;  all rules of-puNctuation-were?simply    ignOred  !this Is, read-able.  after    a fashion but'very'unpleasant "toread isnt      It,```

Any good IDE can do the formatting for you. Even if you have a terrible IDE, that's no excuse. I started coding C around 1990, and even without tools to format code, people back then managed to make legible code by manual use of the tab key.

Very simple - every time you enter a new set of braces, you increase by one tab. When you leave that block, you decrease by one tab.

Code:

```int main() {     int x;     int y;     int n;     int m=0;     printf("First Number =");     scanf("%d",&x);     printf("Divide Number =");     scanf("%d",&y);     printf("Loop Number =");     scanf("%d",&n);     while(m<n)     {         x+=y;         printf("%d,",x);     } }```
• 02-22-2013
loserone+_+
Quote:

Originally Posted by whiteflags
Basically all your loops have the same problem. m < n is true forever, because neither variable changes.

lol i forget for adding an increment on behind,
thanks for whiteflags
this problem solved anyway

still i cant figure it out,
why my code is "unreadable" thing,
please tell me to make the code readable for other people to be readin'

by the way this problem solved anyway
• 02-22-2013
AndiPersti
Quote:

Originally Posted by loserone+_+
still i cant figure it out,
why my code is "unreadable" thing,
please tell me to make the code readable for other people to be readin'

Compare your version from post #1 with Cat's version in post #4. Don't you see the difference?

Programming Style - Part 1, Whitespace - Cprogramming.com

Bye, Andreas
• 02-22-2013
loserone+_+
ok thanks, all problems solved