Need a little help with programming in C#

Discussion in 'Web Design & Coding' started by spike228, Feb 15, 2007.

  1. spike228

    spike228 ST 38 VIP Member

    Joined:
    Jul 18, 2004
    Messages:
    2,256
    Likes Received:
    18
    Location:
    Honolulu, Hawaii
    If anyone knows how to program in C#, I have a question.

    This is the part of my code in question:
    Code:
       /* while loop will keep prompting user inputs EOF  */
                while (flag != EOF)
            {
                    /*  user prompt will loop if while statement is true */
                    printf("Enter annual interest rate (in decimal): ");
                    flag = scanf("%f" ,&annual_interest);
    
                    printf("Calculate compounding years, months or days?\n");
                    printf("Enter '1' for years, '2' for months, '3' for days: ");
                    flag = scanf("%f", &compound);
    
            if (compound = 1)
            {        printf("Enter number of years compounding: ");
                    flag = scanf("%f" ,&years);
            }
    
            else if  (compound = 2)
            {       printf("Enter number of months compounding: ");
                    flag = scanf("%f", &months);
                            years = months / 12;
            }
    
            else if (compound = 3)
            {       printf("Enter number of days compounding: ");
                    flag = scanf("%f", &days);
                            years = days / 365;
            }
    
    
    When I enter 1, 2 or 3, for compounding years/months/days, the program is suppose to jump to the next respective user prompt.

    But my problem is that the "if" statements seem to be ignored for some reason. I know that the user is assigning "compound" and the "if" statements should be reading "compound" to see which one of the statements are true. But it simply runs as if there were no "if" statements at all.

    I tried commenting out the first "if" statement and it prompted me for "months" regardless of what number I assign "compound" as. the same happens if I don't comment out the first "if" statement, in which case it would keep prompting me for "years".

    Does anyone know what I am doing wrong?

    Thanks!
     
    spike228, Feb 15, 2007
    #1
    1. Advertisements

  2. spike228

    spike228 ST 38 VIP Member

    Joined:
    Jul 18, 2004
    Messages:
    2,256
    Likes Received:
    18
    Location:
    Honolulu, Hawaii
    okay nm, it was a totally stupid error that I overlooked.

    if anyone is wondering, i used "=" as an equality instead of "==".

    "=" is only used for assignments.
     
    spike228, Feb 15, 2007
    #2
    1. Advertisements

  3. spike228

    Zeus Moderator

    Joined:
    Jun 20, 2005
    Messages:
    2,006
    Likes Received:
    33
    Location:
    Virginia
    Glad I could help ;)

    Actually, I am in the process of learning C, so I was going to whip out my book and see if I could figure it out.
     
    Zeus, Feb 15, 2007
    #3
  4. spike228

    Crimson Devil's Advocate VIP Member

    Joined:
    Aug 21, 2006
    Messages:
    479
    Likes Received:
    3
    Location:
    Norfolk, VA
    I do PERL. Well I try to do PERL.
     
    Crimson, Feb 15, 2007
    #4
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.