-
May 21st, 2009, 02:53 AM
#1
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);
}
-
May 21st, 2009, 04:24 AM
#2
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.
-
May 21st, 2009, 12:04 PM
#3
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
-
May 21st, 2009, 05:12 PM
#4
Re: Help with if else statement please
yeah thanks guys cant believe I overlooked that.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|