CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2009
    Posts
    23

    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);
        }

  2. #2
    Join Date
    Mar 2009
    Posts
    51

    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.

  3. #3
    Join Date
    Jun 2008
    Posts
    2,477

    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

  4. #4
    Join Date
    Mar 2009
    Posts
    23

    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
  •  





Click Here to Expand Forum to Full Width

Featured