#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

# Find Largest Figure And Figure Less Than 20% Of Largest

Member Posts: 2

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

```</p> <pre><code> 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

``````

Tagged:

• Member Posts: 2

Solved:

``````#include<stdlib.h>
#include<stdio.h>

int main()
{
float sales[200], lowsales=0, largest, limit, lower;
int Count1, Count2, Count3, num;

printf("Enter no of figures:");
scanf("%d", &num);

for (Count1=0; Count1<num; Count1++)
{
printf("Enter sales figure # %d: ",Count1+1);
scanf("%f",&sales[Count1]);
}

largest = sales[0];

for (Count2=0; Count2<num; Count2++)
{
if (sales[Count2]>largest)
{
largest = sales[Count2];
}
}
printf("%f\n", largest); //added this just to check that it is setting largest correctly

printf("Sales figures which are less than 20 per cent of largest sales:\n");
limit = largest*0.2;
for (Count3=0; Count3<num; Count3++)
{
if (sales[Count3]<limit)
{
lowsales = sales[Count3]; //you just had them in wrong order ;-)
printf("%f\n",lowsales);
}
}
//system("pause");
return 0;
}

``````