Need URGENT help!!!

This is a discussion on Need URGENT help!!! within the C++ Programming forums, part of the General Programming Boards category; I don't have any idea what to do. Use a double-subscripted array to solve the following problem. A company has ...

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    3

    Need URGENT help!!!

    I don't have any idea what to do.

    Use a double-subscripted array to solve the following problem. A company has 4 salespeople (1-4) who sell 5 different products (1-5). Once a day, each salesperson passes in a slip for each different type of product sold. Each slip contains:
    a. the salesperson number
    b. the product number
    c. the total dollar value of that product sold that day

    thus each salesperson passes in between 0 and 5 sales per day. Assume that the information from all the slips for the 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 the last month, print the results in tabular format with each of the columns representing a particular product. Cross total each row to get the total sales by salesperson for last month. Your tabular printout should include these cross totals to the right of the totalled rows and to the bottom of the totalled columns.
    Last edited by ct28; 09-10-2001 at 05:42 AM.

  2. #2
    Registered User
    Join Date
    Aug 2001
    Posts
    13
    This sound like a typical homework problem... witch means _you_ are suposed to solve it! So my advice is that you realy try to solve the problem, and then if you encounter a problem you post here again and try to specify exactly what part of the homework you're stuck on..

    I won't do you're homework for you...

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    3

    Sorry!!

    Sorry to upset you but this where I am up to and do not know how to put the totals into the table. I have tried to solve it.

    #include <iostream>
    #include <iomanip>
    #define TAB '\t'
    void main()
    {
    int i, j, a, b;
    const int salesperson = 4;
    const int products = 5;
    int sales[salesperson][products];
    for (i = 1; i < salesperson; i++)
    {
    for (j = 1; i < products; i++)
    {
    cout << "Input salesperson's number: ";
    cin >> sales[i][j];
    cout << "Input product number: ";
    cin >> sales[i][j];
    cout << "Input total value of that product sold that day: ";
    cin >> sales[i][j];
    } // end of for j loop
    } // end of for i loop

    cout << "Summary Table";

    for (a=1; a<5; a++)
    {
    cout << setw(10) << "Product " << a;
    } // end of for a loop

    cout << setw(10) << "Total \n";

    for (b=1; b<6; b++)
    {
    cout << "Salesperson " << b << endl;
    } // end of for b loop

    cout << "Total ";

    return 0;
    } // end of main

  4. #4
    Registered User
    Join Date
    Aug 2001
    Posts
    155
    I find the first task in such a problem is to restate the problem in your own words. The way I see it is you will have 600 (assume 30 days in a month and five slips per day per each of 4 salespeople.) sales slips. Each slip will have the sales persons number, the product number, and the total dollar value of the product sold for that day. Your task is to add up all the slips for the month and then provide a table summarizing the sales information by sales person and product providing totals including row and column totals where products are columns and sales person rows.

    Therefore, I would consider doing this.

    Create a global datatype called slip from a struct. It will have three members one each-- the salespersons number, the product number, and the dollar total of sales for that product.

    In main you could create a 1D array of 600 slips and a 2D array of ints (or doubles if sales totals are of decimal value) to hold the totals. The 2D array will have the number of salespersons plus one (the extra element is for the totals) as rows and the number of products plus one (the extra element is for totals) for columns. The 2D array should have all elements initialized to zero. You could use the index 0 for totals and use row index 1- 4 for salespersons with column index 1 - 5 for products or you could let salespersons be represented by indexes 0 - 3 and product totals in index 4 with products in column indexes 0 - 4 and salesperson totals in column index 5, either way works.

    Once you have the arrays set up you can loop through the slip array and add the sales value of each slip to the three appropriate elements of the 2D array (individual salesperson by product in totals[salesperson][product], product sales totals in totals[0 or 4 whichever you chose][product], and salesperson total sales in totals[salesperson][0 or 5 whichever you chose]). If you are not familiar with referencing members of a struct you use the dot operator. Since each element of the slips array is an instance of slip rather than salesperson as the subscript for the 2D array you would use something like this as the subscript for the totals array-- slips[i].salespersonNumber or slips[i].productNumber or slips[i].salesAmount.

    When you are all done with the loop you can then print out the data in an appropriate format.

    In the code you have posted you appear to have merged the data gathering required for the sales slip array with the data in the sales summary array. This won't work. Separating the data gathering from the data summarizing should make things easier for you.

  5. #5
    Registered User
    Join Date
    Aug 2001
    Posts
    13
    hi, again.. sorry if I was a bit rude earlier.. nothing personal and I hope it doesn't intimidate you from posting again..

    The answer above is good so I'm just going to point out one little subtile errorprone thing in you existing code:

    for (i = 1; i < salesperson; i++) {
    for (j = 1; i < products; i++) {

    Notice that you used 'i' in the later two operations of the 'j' for-loop, .. nasty copy/paste error.

    - Anders

  6. #6
    Registered User
    Join Date
    Sep 2001
    Posts
    3

    Thumbs up

    Thanks for your help! I should of posted the source code were I was stuck on. I know in the future to do that.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Urgent Help Needed In Writing Algorithm!!
    By Vikramnb in forum C++ Programming
    Replies: 1
    Last Post: 01-09-2009, 11:46 AM
  2. beginner plzz help urgent
    By sara101 in forum C Programming
    Replies: 11
    Last Post: 01-14-2007, 09:38 PM
  3. pls help me urgent..
    By intruder in forum C Programming
    Replies: 4
    Last Post: 01-13-2003, 03:41 AM
  4. Help Needed: Borland C++ 5.5 Installation - URGENT!
    By Linette in forum C++ Programming
    Replies: 12
    Last Post: 03-09-2002, 05:44 PM
  5. Help.... Urgent... Thanks!
    By weihann in forum C Programming
    Replies: 0
    Last Post: 02-27-2002, 09:15 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21