about loops, i'm a n00b

This is a discussion on about loops, i'm a n00b within the C Programming forums, part of the General Programming Boards category; hey, i just got started on C and i already got into a problem with loops. this is what i ...

  1. #1
    Registered User arvidabystrom's Avatar
    Join Date
    Dec 2012
    Location
    london
    Posts
    1

    about loops, i'm a n00b

    hey,
    i just got started on C and i already got into a problem with loops. this is what i wrote:
    Code:
    int main ()
    {
            int days, pennies;
            {
            printf ("days of month: ");
            scanf ("%d", &days);
            } while (days <28 || days>31);
    
    }
    well and if i write any number between 28 and 32 then it passes on to the next step, but i want it to loop and say "days of month" again if writing anything that isn't 28-31 but i clearly failed on that one, cuz when i type in something that isn't between those numbers nothing happens.

    all thanxxx for help.

  2. #2
    Registered User
    Join Date
    Jun 2011
    Posts
    2,706
    It looks like you want to use a "do-while()" loop ... but you're missing the "do".
    For, While and Do While Loops in C - Cprogramming.com

  3. #3
    qny
    qny is offline
    Registered User
    Join Date
    Sep 2012
    Posts
    355
    With a different indentation (more like what the program does) your program looks like this:

    Code:
    int main ()
    {
    
            int days, pennies;
    
            {
                  printf ("days of month: ");
                  scanf ("%d", &days);
            }
    
            while (days <28 || days>31);
    
    }
    Your program is composed of 1 block and 1 (empty) loop. You probably wanted a "do ... while" loop.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. N00b with n00b question (probably a quick one)
    By jester-race in forum C++ Programming
    Replies: 8
    Last Post: 11-05-2011, 08:01 PM
  2. Replies: 3
    Last Post: 06-01-2011, 05:19 PM
  3. help with loops - super n00b
    By antipesto93 in forum C++ Programming
    Replies: 2
    Last Post: 06-15-2010, 10:57 AM
  4. n00b Question- Loops
    By asmitzer in forum C Programming
    Replies: 3
    Last Post: 02-16-2010, 04:53 PM
  5. n00b
    By newbie10101 in forum C++ Programming
    Replies: 6
    Last Post: 03-24-2002, 03:03 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21