need help if else

hi guys i am trying to program this
1. Write a program to compute the pension of an employee
If the person is male
Age >= 90 pension is 4000
Age >= 60 pension is 6000
Age < 60 pension is 0
If the person is female
Age >= 90 pension is 3000
Age >= 60 pension is 5000
Age < 60 pension is 0
my code is this i am having errors in if else
#include<stdio.h>
int main()
{
int i,j;
char gender;
printf ("enter m for male and f for female\n");
scanf("%c",&gender);}

if (gender==m)
{
printf("enter your age");
scanf("%d",&i);

if(i>=90);
{(printf("your pension is 4000"));}
if(i>=60);
{printf("your pension is 2000");}


if (i<60);
printf("no pension");
}
if (gender==f)
{
printf("enter your age");
scanf("%d",&i);
if (i>=90);
{printf("your pension is 5000");

}else (i>=600);
{printf("your pension is 2000");}
else (i>=30);
{printf("your pension is 0");}

}
could you guys pointout any mistakes or better solution
Please use coding tags for future posts.. it helps the users read (http://www.cplusplus.com/articles/jEywvCM9/)

if(i>=60); should be else if(i>=60) {}
If it's not else if then both i>= 90 and i>=60 is true so both are printed.

Likewise for female.

Consider using else ... instead of if(i<60).

If conditions are not supposed to have a semicolon. If you put a semicolon then the if condition has no corresponding block. So remove those semicolons that are after if. Check your braces and parenthesis after correcting the above and you should be good. ;)
Last edited on
I believe that is gender bias. I recommend removing the gender.
If your in the US, no one is going to retire at 90.
I'd recommend 65, 70 and 75 or something more common in your area.
I'm with @SamuelAdams on the gender bias bit. I'm staggered that anyone got away with setting that question!

Which educational institution, in which country, are you @even better?
m is a variable. 'm' is a character.
see: if (gender==m) //this looks wrong

little things you will learn, consider
prompt and get age and gender etc all up front. you repeat the age code twice once for each gender, this is bad practice (never repeat code without a good reason).

basic logic
if age >= 90
else
if age >= 60
else //default, no condition
no pension

and then there is just extreme cuteness:
it looks like the female pension is the male pension - 1000.
so you could do this

check age
if age vs 60
pension = 5000-gender; //5000 or 4000, gender is either 0 or 1000 depending on gender

and so on. This would remove a lot of conditions and simplify the code. Rather than repeat the print statement, just have one at the end based off calculated pension.

that looks like this
printf("your pension is %i", pensionvalue); //%i is a placeholder for int, it will show the value of the variable pensionvalue there in the text.
Last edited on
Who gives a f***, it's a contrived programming assignment meant to teach basic 'if' logic. It doesn't even make sense, pension is based off more than just age and sex.
Trust me Ganado, this is going to end up costing some professor a job.
According to the code, he's paying the women more.. no? If the pension is higher for women it's not because of discrimination or sexism but instead in the interest of women. I know it sounds absurd but that's how some countries deal with minorities, they promote them by giving them reservations etc.

Either way it's not a big issue even if he were paying men more and I'm sure nobody would go so far as to confess the writer. Well I guess I can't say that in 2018.. lot's of weird stuff and a lot more weird people oh and 2000 more new genders.
THANKS TO ALL
Topic archived. No new replies allowed.