C and C++

Moderators: None (Apply to moderate this forum)
Number of threads: 28629
Number of posts: 94611

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
please help clean up code!!! Posted by jwood44 on 5 Apr 2012 at 12:00 PM
this is the question:

Hello, I am attempting to write a program in c. First I will put in my program so far. If you are willing to help I would appreciate it. It compiles ok but does not work correctly.

Here is what I am trying to accomplish:
Use a double-subscripted array to solve the following problem. A company has four salespeople (1 to 4) who sell five different products (1 to 5). Once a day, each salesperson passes in a slip for each different type of product sold. Each slip contains:

* The salesperson number
* The product number
* The total dollar value of that product sold that day

Thus, each salesperson passes in between 0 and 5 sales slips per day. Assume that the information from all of the slips for last month is available. Write a program that will read all this information for last month’s sales and summarize the total sales by salesperson by product. All totals should be stored in the double-subscripted array sales. After processing all the information for last month, print the results in tabular format with each of the columns representing a particular salesperson and each of the rows representing a particular product. Cross total each row to get the total sales of each product for last month, and cross total each column to get the total sales by salesperson for last month. Your tabular printout should include these cross totals to the right of the totaled rows and to the bottom of the totaled columns.

Hints:
For each of 4 salespeople, you need to read in the sales for each of 5 products for each of 20 days.
As you are developing your program, you may want to test for smaller numbers of salespeople, products, and/or days, to avoid inputting large numbers of values each time. When you get the program working for smaller numbers, increase to the required values.

and this is the code I have so far

#include <stdio.h>

#define PEOPLE 5
#define PRODUCTS 6

int main()
{
    int i= 0;
    int j= 0;       
    int sales[3][4] = {0};
    int totalSales;
    int productSales[4] = {0};
    int salesPerson;
    int product= 1;
    int productnumber;
    
    printf("Enter the salesPerson number (1-4). Enter salesPerson number -1 to end:");
    scanf("%d", &salesPerson);
    while (salesPerson != -1)
    { 
    
        if (salesPerson != -1 && salesPerson>0&&salesPerson<5)
        {
            printf("ProductNumber:\n");      
            scanf("%d", &product);
            printf("Number of Product Units Sold:\n");
            scanf("%d\n", &productnumber);
            
        }
    }
    printf("The total sales for each salesPerson are displayed at the\n");
    printf("bottom of each column,and the total sales for each product\n");
    printf("are displayed at the end of each row.\n "); 
    
    {
        printf("Total\n");
    }
    for (i =0;i<= 5;i++)
    {
        totalSales = 0;
        printf("%d", i);
        
        for (j=0;j<= 4;j++)
        {
            totalSales+=sales[i][j];
            printf( "%d", sales[i][j]);
        }
        
        
        printf("totalSales=\n");
    }
    
    
    /*display total product sales*/
    for (i =0;i< 5;i++)
    {
        totalSales = 0;
        
        for (j=0;j<6;j++)
        {
            totalSales+=sales[j][i];        
            
        }
        if(i==0)
        {
            printf("Total %d\n",totalSales);     
        }
        else       
            printf("%d\n",totalSales);       
    }
    return 0;
}

Report
Re: please help clean up code!!! Posted by PerlongFiona on 6 Apr 2012 at 3:09 AM
It is reall so difficult, I am sorry.

Report
Re: please help clean up code!!! Posted by PerlongFiona on 6 Apr 2012 at 3:11 AM
It is reall so difficult, I am sorry.




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.