Thread: Question ab 2 if statements...

  1. #1
    Registered User
    Join Date
    Jul 2002
    Posts
    48

    Question ab 2 if statements...

    hmm... i don't know what i'm doing wrong here (with the 2 'if' statements... the 1st one works perfectly (Original Broker's Commission), but the 2nd doesn't (Rival Broker's Commission)

    /*broker's commission... update~!!! */
    /* DATE: 07-22-02 */

    #include <stdio.h>

    int main()
    {
    float commission, number, price, value, value2, shares;

    printf("Enter number of shares: ");
    scanf("%d", &number);
    printf("Enter price per share: ");
    scanf("%f", &price);

    value = shares * price;

    if(value < 2500.00)
    commission = 30.00 + .017 * value;
    else if (value < 6250.00)
    commission = 56.00 + .0066 * value;
    else if (value < 20000.00)
    commission = 76.00 + .0034 * value;
    else if (value < 50000.00)
    commission = 100.00 + .0022 * value;
    else if (value < 500000)
    commission = 155.00 + .0011 * value;
    else
    commission = 255.00 + .0009 * value;

    if (commission < 39.00)
    commission = 39.00;

    if(shares < 2000)
    value2 = 33.00 + .03 * value;
    else if (shares >= 2000)
    value2 = 33.00 + .02 * value;

    printf("Original Broker's Commission: $%.2f\n", commission);
    printf("Rival Broker's Commission: $%.2f\n", value2);

    return 0;
    }

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    You have a dozen or so if statements. I don't feel like compiling this, so how about you state which one is not working.

    First off, for the record, it's generally a BadThing(TM) to use floating point numbers for if checks.

    That being said, this is the one that is probably your problem statement:

    > if(shares < 2000)

    Change this to:

    if( shares < 2000.0 )

    Or simply make 'shares' an integer.

    Additionally, you don't need the second "if" check there. Obviously if shares is not less than 2000, then it has to be greater than or equal to 2000.

    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Multiple If Statements Question.
    By thekautz in forum C++ Programming
    Replies: 3
    Last Post: 11-07-2008, 03:06 PM
  2. If statements question.
    By thekautz in forum C++ Programming
    Replies: 3
    Last Post: 11-06-2008, 04:09 AM
  3. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  4. opengl DC question
    By SAMSAM in forum Game Programming
    Replies: 6
    Last Post: 02-26-2003, 09:22 PM
  5. Question about linked lists.
    By cheeisme123 in forum C++ Programming
    Replies: 6
    Last Post: 02-25-2003, 01:36 PM