I have been studying C language for some time now, and I have a certain bug that I can't seem to be able to fix.
As part of my revision, I started coding a very simple app for stock market.
Whenever I build and run the program, the program doesn't wait for user input to enter (Y) or (N), and skips checking [If] and [else if], and instead executes [else] condition.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int Salary;
char key;
printf("Enter your salary: \n");
scanf("%d",&Salary);
printf("Your salary = %d.\n", Salary);
if(Salary<='10000'&&Salary>'5000')
{
printf("Congratulations, You are a Platinum-Tier Client!\n");
printf("Do You want to view our specifically-tailored offers for you?\n");
printf("Type \"Y\" for Yes, and \"N\" for No.\n\n\n");
key=getchar();
fflush(stdin);
if(key=='Y')
{
printf("Here are our offers for you, enjoy!\n\n");
printf("Kindly Type the number of the offer you want then press Enter.\n");
printf("1- Real Estates.\n");
printf("2- Stocks.\n");
printf("3- Bonds.\n");
printf("4- STRIPS.\n");
printf("5- Funds.\n");
}
else if(key=='N')
{
printf("Well! Have a nice day!\n");
printf("Kindly press Enter to exit!\n");
}
else
{
printf("Wrong choice!\n");
printf("Type \"Y\" for Yes, and \"N\" for No.\n\n\n");
}
}
else if(Salary<='5000'&&Salary>='3000')
{
printf("Congratulations, You are a Gold-Tier Client\n");
printf("Do You want to view our specifically-tailored offers for you?\n");
printf("Type \"Y\" for Yes, and \"N\" for No.\n\n\n");
key=getchar();
if(key=='Y')
{
printf("Here are our offers for you, enjoy!\n\n");
printf("Kindly Type the number of the offer you want then press Enter.\n");
printf("1- Real Estates.\n");
printf("2- Stocks.\n");
printf("3- Bonds.\n");
printf("4- STRIPS.\n");
printf("5- Funds.\n");
}
else if(key=='N')
{
printf("Well! Have a nice day!\n");
printf("Kindly press Enter to exit!\n");
}
else
{
printf("Wrong choice!\n");
printf("Type \"Y\" for Yes, and \"N\" for No.\n\n\n");
}
}
else if(Salary<'3000'&&Salary>'1')
{
printf("Congratulations, You are a Silver-Tier Client\n");
printf("Do You want to view our specifically-tailored offers for you?\n");
printf("Type \"Y\" for Yes, and \"N\" for No.\n\n\n");
key=getchar();
if(key=='Y')
{
printf("Here are our offers for you, enjoy!\n\n");
printf("Kindly Type the number of the offer you want then press Enter.\n");
printf("1- Real Estates.\n");
printf("2- Stocks.\n");
printf("3- Bonds.\n");
printf("4- STRIPS.\n");
printf("5- Funds.\n");
}
else if(key=='N')
{
printf("Well! Have a nice day!\n");
printf("Kindly press Enter to exit!\n");
}
else
{
printf("Wrong choice!\n");
printf("Type \"Y\" for Yes, and \"N\" for No.\n\n\n");
}
}
else
{
printf("Sorry! No offers for you!\n");
}
return 0;
}
The result is always (If I write 5000 for example):
Enter your salary:
5000
Your salary = 5000.
Congratulations, You are a Silver-Tier Client
Do You want to view our specifically-tailored offers for you?
Type "Y" for Yes, and "N" for No.
Wrong choice!
Type "Y" for Yes, and "N" for No.
What am I missing here?
Thank you for your help, and sorry if the question is kind of lame.