Thread: about loops, i'm a n00b

  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
    4,513
    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
    Registered User
    Join Date
    Sep 2012
    Posts
    357
    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, 07:01 PM
  2. Replies: 3
    Last Post: 06-01-2011, 04:19 PM
  3. help with loops - super n00b
    By antipesto93 in forum C++ Programming
    Replies: 2
    Last Post: 06-15-2010, 09: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