two demensional arrays

Hi again,

Im working on a program to learn two dimensional arrays. The program needs to take a set of predefined numbers in the array and multiply them by a user imputed number. The numbers are sales and the user number is a percentage that is the bonus rate. It needs to show the sales persons number 1 to 10, total sales, and total bonus to all sales persons.

I have a grasp on displaying what is in the array, but turning the imputed number in to a percentage ( divide by 100? ) and then multiplying the entire array by that number seems to be what im stuck on. Any help is appreciated.


this is what i have so far.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <iostream>
using namespace std;

int main()
{
    //declaring array
    double sales[10][3] = {{2400, 3500, 2000}, {1500, 7000, 1000}, {600, 450, 2100},
    {790, 240, 500}, {1000, 1000, 1000}, {6300, 7000, 8000,}, {1300, 450, 700}, 
    {2700, 5500, 6000}, {4700, 4800, 4900}, {1200, 1300, 400}};
    
    //enter data
    
  
           
    
    //display
    for (int person = 0; person < 10; person += 1)
    {
        cout << "Sales Person " << person + 1 << ": " << endl;
        for (int month = 0; month < 3; month += 1)
        {
            cout << "Month " << month + 1 << ": ";
            cout << sales[person][month] << endl;
        }//end for
        
    } //end
    
   cin.get();
    
    
}
closed account (N85iE3v7)
If you want to multiply an 2D array by a value, you have to iterate through its contents.

Normally, using your code above:

1
2
3
4
5
6
7
8
9
10
11
    double a = 100;

    for (int person = 0; person < 10; person++)
    {
        for (int month = 0; month < 3; month++)
        {
               sales[person][month] = sales[person][month]/100;
        }//end for
        
    } //end


If you do this you will change the original array, so it might be a good idea to have a new array to hold these new values.

Topic archived. No new replies allowed.