Very very new to C programming and I've created an infinite loop, please help

This is a discussion on Very very new to C programming and I've created an infinite loop, please help within the C Programming forums, part of the General Programming Boards category; Hi all I'm playing with C code after coding with C# and I was trying to validate that user in ...

  1. #1
    Registered User
    Join Date
    Jul 2009
    Posts
    2

    Question Very very new to C programming and I've created an infinite loop, please help

    Hi all

    I'm playing with C code after coding with C# and I was trying to validate that user in putted data was an integer, some how all I've managed to do is create an infinite loop. Could someone please look over my code and let me know how to get the desired result.

    Thanks
    Code:
    printf("Please enter the number of rectangles you wish to add: ");
    
    isInteger =scanf("%d", &noRectangles);
    
    while (isInteger == 0)
    {
    
    printf("Error: Sorry the data you entered was not numerical. Please enter a numerical value. \n");
    
    printf("Please enter the number of rectangles you wish to enter: ");
    
    isInteger =scanf("%d", &noRectangles);
    continue;
    
    }

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,600
    Read this.
    Code:
    if( numeric_limits< byte >::digits != bits_per_byte )
        error( "program requires bits_per_byte-bit bytes" );
    24bbs.cpp

  3. #3
    Webhead Spidey's Avatar
    Join Date
    Jul 2009
    Posts
    285
    Also, you don't need the explicit continue at th end of your loop, it will do that automatically.
    Spidey out!

  4. #4
    Registered User
    Join Date
    Jul 2009
    Posts
    2
    Thank you, it worked a treat

Popular pages Recent additions subscribe to a feed

Tags for this Thread


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