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

  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,708
    Read this.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  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