error non-lvalue in assignment

This is a discussion on error non-lvalue in assignment within the C Programming forums, part of the General Programming Boards category; I get error msg non-lvalue in assignment(mark with red color) Code: // Write a program that asks the user for ...

  1. #1
    Registered User abhijitnumber1's Avatar
    Join Date
    Jun 2012
    Location
    kolkata
    Posts
    5

    Talking error non-lvalue in assignment

    I get error msg non-lvalue in assignment(mark with red color)

    Code:
     // Write a program that asks the user for a 24-hour time,// Then displays the time in 12-hour form:
    // CREATED BY: ABHIJIT DAS
    // DATE: 28.6.2012
    
    
    #include<stdio.h>
    #include<conio.h>
    main()
    
    
    {
          int hour, min, hour_12;
          
          printf("Enter a 24-hour time(as xx:xx):\n");
          scanf("%d:%d", &hour, &min);
          
         
                  
          hour_12 = hour - 12;
          
          if( 0 = hour_12  &&  0 = min)
          {
                  printf("The time is 12:00 AM");
                  }
         else if(hour <= 24)
          {
          printf("Equivalent 12-hour time: %d:%d", hour_12, min);
          }
         
          else printf("Invaled time");
          if(hour = 0)
          {
                  printf("You enter an invaled time");
                  }
                  
                  else if(hour > 0 && hour <= 12)
                  {
                       printf("AM");
                       }
                       else if(hour > 12 && hour <= 24)
                       {
                            printf("PM");
                            }
                            else printf("You enter an invaled time");
                            
                            getch();
                            return 0;
                            }
    help me. Thanks.

  2. #2
    Registered User
    Join Date
    Jun 2011
    Posts
    2,650
    Code:
    if( 0 = hour_12  &&  0 = min)
    Be careful, you're mixing up the assignment operator (=) and the relational operator (==).

  3. #3
    Registered User abhijitnumber1's Avatar
    Join Date
    Jun 2012
    Location
    kolkata
    Posts
    5
    Thanks for your help matticus.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. error: lvalue required, pretty sure it's an lvalue
    By brandones in forum C Programming
    Replies: 18
    Last Post: 08-22-2011, 09:06 PM
  2. error: lvalue required as left operand of assignment
    By owjian1987 in forum C Programming
    Replies: 5
    Last Post: 02-11-2011, 12:34 PM
  3. Replies: 3
    Last Post: 06-01-2010, 07:22 AM
  4. :523: error: invalid lvalue in assignment
    By nasim751 in forum C Programming
    Replies: 10
    Last Post: 04-14-2008, 05:08 AM
  5. Error msg: "invalid lvalue in assignment"
    By mike00800 in forum C Programming
    Replies: 5
    Last Post: 11-07-2007, 08:38 AM

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