PROBLEM 6.22 - ANALYSIS

Problem Statement:

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

1. The salesperson number
2. The product number
3. The total dollar value of that product sold on that day.
Write a program that reads in (from the user) all the information from the previous month's sales. Your program should read in information until the user is finished entering (they will indicate this by entering the sentinel value -1 for the salesperson number) and summarize the total sales by salesperson and product. After processing the information, your program should print the results in a tabular format with each of the rows representing a particular salesperson and each of the columns representing a particular person. Cross total each row to get the total sales of each product for last month; cross total each column to get the total sales of each product 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.

Sample Run:


Enter the salesperson, product, and total sales.
(Enter -1 for the salesperon to end input):  2 4 78.99

Enter the salesperson, product, and total sales.
(Enter -1 for the salesperon to end input):  3 4 127.50

Enter the salesperson, product, and total sales.
(Enter -1 for the salesperon to end input):  2 2 85.60

Enter the salesperson, product, and total sales.
(Enter -1 for the salesperon to end input):  1 3 150.44

Enter the salesperson, product, and total sales.
(Enter -1 for the salesperon to end input):  1 3 22.50

Enter the salesperson, product, and total sales.
(Enter -1 for the salesperon to end input):  1 4 240.60

Enter the salesperson, product, and total sales.
(Enter -1 for the salesperon to end input):  -1


        The total sales for each salesperson
        are displayed at the end of each row
        and the total sales for each product
        are displayed at the bottom of each column

Sales-                      Products
person        1       2       3       4       5    Total
  1         0.00    0.00  172.94  240.60    0.00  413.54
  2         0.00   85.60    0.00   78.99    0.00  164.59
  3         0.00    0.00    0.00  127.50    0.00  127.50
  4         0.00    0.00    0.00    0.00    0.00    0.00
Total       0.00   85.60  172.94  447.09    0.00


INPUT VARIABLES

Description
Name
Data Type
Rationale
array to hold the entered sales totals sales[4][5] float This array will hold sales totals (dollar values, which are decimal values) for 4 people and 5 products.
salesperson's number salesPerons int problem states that the salespeople are numbered 1 through 4 (integer values)
product's number product int problem states that the products are numbered 1 through 5 (integer values)
value of the sales made value float sales are dollar values (which are decimal values)

INTERMEDIATE VARIABLE

Description
Name
Data Type
Rationale
loop counters i, j int counting numbers are integers

OUTPUT VARIABLES

Description
Name
Data Type
Rationale
array to keep track of running totals by product productSales[5] float dollar values are decimal values
total value of the sales of each salesperons totalSales float dollar values are decimal values


ALGORITHM

For main:

1. Declare and initialize variable.

2. Call the function to read in the sales from the user

3. Call the funtion to display the table header

4. Call the function to display the sales


For getSales:

1. Declare local variables

2. Prompt user for input

3. While user has not entered sentinel value (-1)

3.1 Read in input

3.2 Prompt user for input


For printHeader:

1. Display explanation

2. Display column headings


For printSales:

1. Declare and initialize local variables

2. Loop through each salesperson

2.1 Initialize salesperson's running total to 0

2.2 Print product number

2.3 Loop through each product

2.3.1 Add sales to the salesperson's running total

2.3.2 Add sales to the product's running total

2.3.2 Display the sales for the current product and salesperson

2.4 Display the salesperson's total
3. Display the product totals


SOLUTION