Hi, I have written some which needs to:
- read in 200 floating point numbers that
represent the sales figures of 200 sales staff.
- once the 200 numbers have been read in code should find the largest individual sales figure
- code should then use this value to display all those sales figures which are less than 20 % of the highest value.
Here is my code so far, however, for largest
it currently only prints the last entry scanned in ...
int main() {
float sales[200], lowsales = 0, largest, limit, lower;
int i, l, j, k, num;
printf("Enter no of figures:");
scanf("%d", & num);
for (l = 0; l < num; l++) {
printf("Enter sales figure # %d: ", l + 1);
scanf("%f", & sales[i]);
}
largest = sales[0];
for (j = 0; j < num; j++) {
if (sales[i]>largest) {
sales[i] = largest;
// printf("Inline largest: %f\n", largest );
}
}
printf("largest: %f\n", largest);
printf("\nSales figures which are less than 20 per cent of largest sales:\n");
limit = largest * (0.2);
for (k = 0; k < num; k++) {
if (sales[i] < limit) {
lowsales = sales[i];
}
printf("lowsales: %f\n", lowsales);
}
//system("pause");
return 0;
}
This the output I get from this code:
Enter no of figures:4
Enter sales figure # 1: 7979.999
Enter sales figure # 2: 8989.777
Enter sales figure # 3: 3.455
Enter sales figure # 4: 5959.555
largest: 5959.555176
Sales figures which are less than 20 per cent of largest sales:
lowsales: 0.000000
lowsales: 0.000000
lowsales: 0.000000
lowsales: 0.000000
Could I ask if anyone would mine to please help me correct what I have done so far ?
It looks like you're new here. If you want to get involved, click one of these buttons!
Comments
Solved: