Error in Compiling Basic Program

Hey Im new on this forum,

I am having some error with my coding, I get the following error when trying to compile:

non-lvalue in assignment

This is my code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <stdio.h>

int age, yrsOfService, countMale, countFemale, countTotal;
float salary, monthlyWage, weeklyWage, severance, severanceTotal;
char gender;

int main()

{
    printf("\n\n\n\t\t ***** Pension Calculator *****");
    
    printf("\n\n\t\tPlease enter your Salary: ");
    scanf("%f", &salary);
    
    printf("\n\n\t\tPlease enter your Age: ");
    scanf("%d", &age);
    
    printf("\n\n\t\tPlease enter Gender (M/F): ");
    scanf("%c", &gender);
    
    printf("\n\n\t\tPlease enter Years of Service: ");
    scanf("%d", &yrsOfService);
    
    monthlyWage=salary/12;
    weeklyWage=salary/52;
    
    if(gender='M' && age>=45 || gender='F' && age>=40)
    {
      if(gender='M')
        {
          countMale++;
          }
           else
           {
             countFemale++;
               }
               
      severance=2*weeklyWage*yrsOfService;
      }
      else
      {
                if(gender='M')
        {
          countMale++;
          }
           else
           {
             countFemale++;
               }
        severance=weeklyWage*yrsOfService;
        }
        
        
      
    if(severance<monthlyWage)
    {
      severance=monthlyWage;
      }
      else
      {
}
    
    countTotal=countMale+countFemale;
    severanceTotal=severance;
    
    printf("\n\n\t\t\t Number\t Pension");
    printf("\n\t\t Male\t %d\t %7.2f", countMale,  severance);
    printf("\n\t\t Female\t %d\t %7.2f", countFemale, severance);
    printf("\n\t\t Total\t %d\n %7.2f", countTotal, severanceTotal);

}
    


if(gender='M' && age>=45 || gender='F' && age>=40)

If you're going to chain your logical operations like this, you need to use parentheses, and the == operator to test for equality:

if( ((gender=='M') && (age>=45)) || ((gender=='F') && (age>=40))

Look through your code and replace the other erroneous uses of = with ==.
You don't need extra parentheses but they can help readability.
In this case, not using the parentheses caused a compilation error, although interestingly a compilation error that also would not have happened had the == operator been used. Ironically, the poor form (lack of parentheses) showed up the logical error (assignment instead of equality-testing).
Last edited on
Not if he replace = with ==.
Thanks a lot mate!

Fixed it ! :)
Topic archived. No new replies allowed.