Help with if else statement please
This code is designed for "C" weather thats that same as C sharp im not sure so sorry about that.
Im having trouble in this program where the user is to input eigther 'F' or 'S'. After you make the selection it just prompts "Please enter the amount owed" regardless if an 'F' or 'S' is inputted.
Can anyone see what I've done wrong? it looks logical to me.
Code:
do
{
printf("Please enter 'F' for fee-paying or 'S' for Social Security: ");
scanf("%c", &person.feeorss);
person.feeorss = _toupper(person.feeorss);
}while( ((person.feeorss != 'F') && (person.feeorss != 'S')) );
if(person.feeorss = 'F')
{
printf("Please enter the amount owed: ");
fflush(stdin);
scanf("%lg",&person.payment.amountowed);
}
else if(person.feeorss = 'S')
{
printf("Please enter Social Security Number: ");
fflush(stdin);
gets(person.payment.sscode);
}
Re: Help with if else statement please
That is C and therefore you should really ask here: http://www.codeguru.com/forum/forumdisplay.php?f=9
The answer to your question is that you should use == instead of = in the if statements.
:)
Re: Help with if else statement please
Just to expand upon what Zaccheus@Work has already said, the '=' sign is an assignment operator and '==' tests for equality. So, what you are doing is assigning the value 'F' to person.feeorss and then testing whether that is true or false. Seems like you should probably study a bit more before jumping in :)
Re: Help with if else statement please
yeah thanks guys cant believe I overlooked that.