Thread: Sales Comission

  1. #1
    Registered User
    Join Date
    Oct 2011
    Posts
    20

    Sales Comission

    Hello again. doing a question in which I am to read the gross sales of a sales person and calculate their salary , which is 200 + 9% of gross salary. Then I am to count the number of workers between 200 and 299 salary etc. My solution compiles. But when I run it seems to be working but it reports all salaries as 0. I'm sure I've made a simple mistake somewhere but i am unable to find it. Hopefully someone could help me. Thanks.
    Code:
    #include<stdio.h>
    #include<stdlib.h>
    #define SIZE 100
    
    
    
    
    int main()
    {
        float salary[SIZE];
        float sales[SIZE];
        int i , j , num , counter;
        int r = 0;
        int limitDown = 200;
        int limitUp = 300;
    
    
        printf("Enter number of people in company(must not exceed 100)\n");
        do
        {
            scanf("%d" , &num);
            if ((num > 100) || (num < 0))
            {
                printf("Number of people cannot exceed 100 or be below 0, enter again:\n");
            }
        }while((num > 100) || (num < 0));
        for (i = 0; i < num; i++);
        {
            printf("Enter a workers gross sales\n");
            scanf("%f" , &sales[i]);
            salary[i] =  200 + (0.9 * sales[i]);
        }
        for(i = 0; i < 9; i++)
        {
            for(j = limitDown; j < limitUp; j++)
            {
                for(counter = 0; counter < num; counter++)
                {
                    if (limitDown < 1000)
                    {
                       if ((salary[counter] >= limitDown) && (salary[counter] < limitUp))
                       {
                           r++;
                       }
                    }
                    else
                    {
                        if(salary[counter] >= limitDown)
                        {
                            r++;
                        }
                    }
                }
            }
            if (limitDown < 1000)
            {
            printf("Number of people salaries %d and %d : %d\n" , limitDown , limitUp - 1 , r);    
            }
            else
            {
               printf("Number of people salaries %d and beyond: %d\n" , limitDown  , r);
            }
            limitUp += 100;
            limitDown += 100;
            r = 0;
        }
        system("PAUSE");
        return 0;
    }

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Add a printf() after line 31 to display each salary as it's calculated.

  3. #3
    Registered User
    Join Date
    Oct 2011
    Posts
    20
    I found an error where I had a ; onthe for loop in line 27 , thanks to the printf. but now i get the correct result times 100 when I print r.

  4. #4
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Ok that would indicate a flaw in your loop structures... you're doing something way too often.

    Frankly I would take a somewhat different approach to calculating how many are at each salary level... If you establish a fixed number of levels (as it appears you tried to do) this too can be an array... this time of integers. Once you calculate the actual salary all you need to do is subtract 200 and divide by 100 ... the result is their salary level... thus...
    Code:
    level[ (int)((salary[i] - 200) / 100) ]++;
    ... gives you a counter for each level. You can do this as you're entering their data, no need for complex loop structures to try to do it after the fact. Just make sure to either cap their salaries or give yourself extra levels, one guy with a big paycheque could cause an out of bounds action on that array if you aren't careful.

    From there writing the printout should be obvious...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. price + sales tax calculator
    By beginnerc in forum C Programming
    Replies: 3
    Last Post: 07-14-2011, 01:45 PM
  2. sales tax
    By Mark_Guy in forum C Programming
    Replies: 0
    Last Post: 10-22-2008, 08:47 AM
  3. Two-dimensional array Sales
    By mikeprogram in forum C++ Programming
    Replies: 7
    Last Post: 12-04-2005, 10:32 PM
  4. Understanding the traveling sales algorithm
    By Axel in forum C Programming
    Replies: 22
    Last Post: 10-22-2005, 10:48 AM
  5. donut sales take a dive
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 24
    Last Post: 07-03-2004, 01:34 PM