Page 1 of 1

## 2 Replies - 642 Views - Last Post: 15 December 2008 - 10:19 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=76846&amp;s=8e5292cf93dc35a0033faae47686b8e2&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 prosty

Reputation: 0
• Posts: 2
• Joined: 15-December 08

Posted 15 December 2008 - 09:37 AM

```#include<stdio.h>

#define SIZE 10

int main()
{
float basewage[SIZE] = {158.00, 147.75, 315.00, 162.25, 220.00, 181.60, 376.90, 168.70, 293.00, 214.30};
float totalwage[SIZE], comm = 3.8;
int sales[SIZE], index = 0, emp_num = 1;

while(emp_num<11)
{
printf("Enter units sold for employee %i\n", emp_num);
scanf("%i",&sales[index]);
fflush(stdin);

if(sales[index]>=1)
if(sales[index]<=5)
;
else
if(sales[index]>=6)
if(sales[index]<=10)
comm='6';
else
if(sales[index]>=11)
if(sales[index]<=15)
comm='9';
else
if(sales[index]>15)
comm = '15';

totalwage[index] = (comm * sales[index]) + basewage[index];
fflush(stdin);
printf("total wage for employee%i is %f\n\n", emp_num, totalwage[index]);

index++;
emp_num++;
}

}
```

I just cant't see were I've gone wrong. the program seems to work correctly up to a sales figure of 5, but anything over and it spits out wrong results
I know its probably something very basic, but i'm at a loss! Any help would be appreciated

Is This A Good Question/Topic? 0

• Saucy!

Reputation: 6246
• Posts: 24,014
• Joined: 23-August 08

Posted 15 December 2008 - 09:52 AM

You shouldn't use fflush(stdin).

This:
```if(sales[index]>=1)
if(sales[index]<=5)
;
else
if(sales[index]>=6)
if(sales[index]<=10)
comm='6';
else
if(sales[index]>=11)
if(sales[index]<=15)
comm='9';
else
if(sales[index]>15)
comm = '15';

```

would be far more readable, as this:
```if(sales[index]>=1 && sales[index]<=5)
{
comm = 3.8;
}
else if(sales[index]>=6 && sales[index]<=10)
{
comm=6.0;
}
else if(sales[index]>=11 && sales[index]<=15)
{
comm=9.0;
}
else
{
comm = 15.0;
}
```

It also fixes your calculation problem, which is because you're assigning a character value to a float variable when you do comm = '6';

### #3 prosty

Reputation: 0
• Posts: 2
• Joined: 15-December 08