If Else and || operator question

This is a discussion on If Else and || operator question within the C Programming forums, part of the General Programming Boards category; I'm trying to make a program which states the day of any date I use using Zeller's algorithm. I don't ...

  1. #1
    Registered User
    Join Date
    May 2011
    Posts
    1

    If Else and || operator question

    I'm trying to make a program which states the day of any date I use using Zeller's algorithm. I don't have the code with me right now. But when I try to write an if statement with an address and an or || operator, it doesn't compile. For example,
    Code:
    int getmonth (int *month, int *date)
    {scanf ("%d/%d", month, date);
    If ((*month==1 || *month == 2) && *date>=1 && *date<=31)
    return 1;
    else return 0;}
    It gives an error for some reason saying that *month must be a modifiable variable. What could be wrong?

  2. #2
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,832
    Must supply address for scanf
    Code:
    scanf ("%d/%d", &month, &date);

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,558
    > I don't have the code with me right now.
    So post it when you do have it.
    Posting what you think you have from memory means we can only make guesses, and be no nearer the real answer.

    > Must supply address for scanf
    But they're already pointers, so that bit should be OK.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    This is why we indent code...
    It's also why you want a syntax highlighting editor...
    Code:
    int getmonth (int *month, int *date)
      {scanf ("%d/%d", month, date);
       If ((*month==1 || *month == 2) && *date>=1 && *date<=31)
         return 1;
       else 
         return 0;}
    Check the first letter on the third line... there's your error.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Question about :: operator
    By C_Sparky in forum C++ Programming
    Replies: 6
    Last Post: 04-04-2010, 09:54 PM
  2. Question about an operator
    By Programmer_P in forum C++ Programming
    Replies: 6
    Last Post: 05-10-2009, 08:58 PM
  3. new operator question
    By abachler in forum C++ Programming
    Replies: 5
    Last Post: 05-22-2008, 02:06 PM
  4. insertion operator question
    By tsubasa in forum C++ Programming
    Replies: 5
    Last Post: 06-08-2006, 01:47 PM
  5. & operator question
    By VanJay011379 in forum C++ Programming
    Replies: 5
    Last Post: 07-10-2002, 06:13 PM

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