# Question ab 2 if statements...

This is a discussion on Question ab 2 if statements... within the C Programming forums, part of the General Programming Boards category; hmm... i don't know what i'm doing wrong here (with the 2 'if' statements... the 1st one works perfectly (Original ...

1. ## 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. 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.