Thread: Looping Failed "Second Problem"

  1. #1
    Registered User loserone+_+'s Avatar
    Join Date
    Dec 2012
    Location
    Indonesia
    Posts
    112

    Exclamation Looping Failed "Second Problem"

    my looping code failed,
    it reads unlimited number readin,
    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?

  2. #2
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    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.

  3. #3
    Registered User
    Join Date
    Dec 2012
    Posts
    17
    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.

  4. #4
    Registered User
    Join Date
    May 2003
    Posts
    1,619
    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);
        }
    }
    You ever try a pink golf ball, Wally? Why, the wind shear on a pink ball alone can take the head clean off a 90 pound midget at 300 yards.

  5. #5
    Registered User loserone+_+'s Avatar
    Join Date
    Dec 2012
    Location
    Indonesia
    Posts
    112
    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

  6. #6
    Registered User
    Join Date
    May 2012
    Posts
    1,066
    Quote Originally Posted by loserone+_+ View Post
    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

  7. #7
    Registered User loserone+_+'s Avatar
    Join Date
    Dec 2012
    Location
    Indonesia
    Posts
    112
    ok thanks, all problems solved

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with looping a "switch" in C programming
    By mousanony in forum C Programming
    Replies: 8
    Last Post: 06-23-2010, 01:36 AM
  2. error "debug assertion failed"
    By roaan in forum C Programming
    Replies: 26
    Last Post: 08-07-2009, 12:36 PM
  3. "failed to grant minimum permission request"
    By namespace::me in forum Tech Board
    Replies: 4
    Last Post: 10-07-2006, 06:58 PM
  4. "itoa"-"_itoa" , "inp"-"_inp", Why some functions have "
    By L.O.K. in forum Windows Programming
    Replies: 5
    Last Post: 12-08-2002, 08:25 AM
  5. "CWnd"-"HWnd","CBitmap"-"HBitmap"...., What is mean by "
    By L.O.K. in forum Windows Programming
    Replies: 2
    Last Post: 12-04-2002, 07:59 AM