Thread: need some more help with interegers in loops.

  1. #1
    Registered User
    Join Date
    Nov 2007
    Posts
    47

    need some more help with interegers in loops.

    inside my function, i need these statements to work.
    the function is.

    void enter(struct date *pdate, char desc[ ])



    Code:
     check = 0;
      while(check != 1)
        {
            printf("Enter the day: (between 1 and 31) ");
            scanf("%d", &pdate->day);
            if (&pdate->day <= 31 && &pdate->day >= 1)
            {
                break;
            }
        }

    im getting the error.
    ISO C++ forbids the comparison between pointers and intergers.

    how would i fix this?

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    Code:
    &pdate->day <= 31 && &pdate->day >= 1
    ampersands should be removed
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Except for the one in the scanf() call, change &pdate->day to pdate->day. You do not want to compare the address of pdate->day, but the value of pdate->day.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #4
    Registered User
    Join Date
    Nov 2007
    Posts
    47
    makes sense ill give it a try

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Too many loops D:
    By F5 Tornado in forum C++ Programming
    Replies: 6
    Last Post: 12-03-2007, 01:18 AM
  2. strings and loops...
    By twomers in forum C Programming
    Replies: 5
    Last Post: 12-12-2005, 11:28 AM
  3. help with arrays and loops
    By jdiazj1 in forum C Programming
    Replies: 4
    Last Post: 11-24-2001, 04:28 PM
  4. for loops in C
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 10-15-2001, 05:09 PM
  5. exiting loops with ease?
    By KingRuss in forum Game Programming
    Replies: 3
    Last Post: 09-24-2001, 08:46 PM