I have been given a problem that asks me to do the following things. Write a program should be stored in two dimensional array. The program must include the following
1. list 4 qtrly sales for 6 divisions of a company.
2. show each division increase or decrease from the previous qtr
3. total the sales for the qtr
4. show the companys increase or decrease from previous qtr...excluding the first qtr.
5. average sales for all divisions that qtr
6. list the division with the highest sales for that qtr.

**now I understand that this is just a site that offers assistance with problems and I must be willing to work as well...so this is what I know...
that the firs size declarator would pertain to the number of rows and the second one is for the number of columns. I also know and understand that a two dimensional array has 2 subscripts...but it all gets a little mirky after that...please help

## All 14 Replies

You're absoluately right. We won't give you a complete code, but we'll help and provide pointers. Firstly, welcome aboard. I can give you a head start, although i wish you'd read up on arrays. You need to tell us if the program is doing to be interactive, will it read data from the infile???
A few things:
1. You can start by delcaring a few variables that you'll need:

``````struct Comp;
float first;
float second;
float third;
float value;
float average;``````

2. With regards to the six divisions...for example, if it's the same company, they perhaps are divided as such:

``````string const N = "North Division";
string const S = "South Division";
string const E = "East Division";
string const W = "West Division";``````

3. Then for the arrays, you may do something like:

``````Comp div[4]

div [0].name= N;
div [1].name= S;
div [2].name= E;
div [3].name= W;``````

``cout<<setw(10)<<"Division"<<setw(15)<<"First Quarter"<<setw(15)<<"Second Quarter"<<setw(15)<<"Third Quarter"<<setw(15)<<"Fourth Quarter"<<setw(15)<<"Total"<<setw(15)<<"Average"<<endl;``

5. Use a FOR loop to go through each division.
6. Do calculation to carry out the averages.
Hope this helps, I know that C++ at times may be overwhelming, but write it out on scratch-paper first to see exactly what you'll need to do. I gave you a jumpstart. You'll also need to provide more information about the requirements of your assignment.

In other words....can you please post what you've got so far?

this is what I have so far

1 //This program demonstrates a two-dimensional array.
2 #include <iostream>
3 #include <iomanip>
4 using name space std;
5
6 int main()
7 {
8 const int NUM_DIVS=6; //Number of divisions
9 const int NUM_QTRS =4; //Number or quaters
10 double sales [NUM_DIVS] [NUM_QTRS]; //Array with 6 rows and 4 columns.
11 double totalSales = 0; //To hold the total sales.
12 int div, qtr; // Loop counters.

At the begining of your code place:
"["CODE=cplusplus"]"
PLACE CODE HERE
At the end of your code, place "["/CODE"]"...without the "

11 double totalSales = 0; //To hold the total sales.

This is to calculate Total sales...not to store it.
2.Where are the headers/titles i pointed out in my previous post? Where is your loops? You've still got quite a bit of work...

You'll also need the following header for mathematical calculations(averages..ect...)

``#include <cmath>``
``````1 //This program demonstrates a two-dimensional array.
2 #include <iostream>
3 #include <iomanip>
4 #include <cmath>
5  using name space std;
6 int main()
7 {
8    const int NUM_DIVS=6;                             //Number of divisions
9    const int NUM_QTRS =4;                           //Number or quaters
10  double sales [NUM_DIVS] [NUM_QTRS];     //Array with 6 rows and 4 columns.
11  double totalSales  = 0;                             //To calculate the total sales.
12  int div, qtr;                                              // Loop counters.
13
14 cout <<"This program will calculate the total sales of \n";
15 cout<<"all th4e company's divisions.\n";
16 cout <<"Enter the following sales information:\\n\n";
17
18  //Nested loops to fill the array with quaterly
19  //sales figures for each division
20  for  (div = 0 ; div< NUM_DIVS; div++)
{
``````

At the begining of your code place:
"["CODE=cplusplus"]", without the ". This way its easier to read...back to your assignment....

16 cout <<"Enter the following sales information:\\n\n";

Given the requirement of your assignment, you may want to break down your program a bit more...example:

``````cout<< "Please enter First Qrt Sales"<<div[j].name<<endl;
cin>>div[j].fir;
cout<< "Please enter Second Qrt Sales"<<div[j].name<<endl;
cin>>div[j].sec;
cout<< "Please enter Third Qrt Sales"<<div[j].name<<endl;
cin>>div[j].thir;
cout<< "Please enter Fourth Qrt Sales"<<div[j].name<<endl;
cin>>div[j].four;``````

OK, now use a nested loop to enter data into array. Here's a very basic outline of a nested loop using for loops. You have to fill in the necessary details as per your project instructions.

``````for() //this loop will control which row you're using
{
for() //this loop will control which column you're using.
{
}
}``````
``````1 //This program demonstrates a two-dimensional array.
2 #include <iostream>
3 #include <iomanip>
4 #include <cmath>
5  using name space std;
6 int main()
7 {
8    const int NUM_DIVS=6;                             //Number of divisions
9    const int NUM_QTRS =4;                           //Number or quaters
10  double sales [NUM_DIVS] [NUM_QTRS];     //Array with 6 rows and 4 columns.
11  double totalSales  = 0;                             //To calculate the total sales.
12  int div, qtr;                                              // Loop counters.
13
14 cout <<"This program will calculate the total sales of \n";
15 cout<<"all th4e company's divisions.\n";
16 cout <<"Enter the following sales information:\\n\n";
17
18  //Nested loops to fill the array with quaterly
19  //sales figures for each division
20  for  (div = 0 ; div< NUM_DIVS; div++)
21   {
22     for (qtr = 0; qtr<NUM_QTRS; qtr++)
23        {
24  cout <<"Division "<< (div + 1);
25  cout <<"' Quarter '<<(qtr +1) <<":\$";
26  cin >> sales [div] [qtr];
27}
``````

Oh goodness....how did you get quote tags in there?? Your formatting should use at the beginning"["CODE=CPLUSPLUS"]" & "["/CODE"]" at the end...
So is the user going to enter all four quarters at once?? I recommend you breaking it down like how i showed in my previous post. Where are your calcualtions for the average??? You're FOR loop, may look something like this, so it can go through all the quarters of the division:

``for (int j=0; j<6; j++)``

i am sorry i am not following you on the quote tag comment...maybe I should just stick to c++ for dummies because I am lost thanks

Is this an school assignment? I'm really sorry if i seem too harsh, I'm still learning c++,but some of the real pro's here won't even bother helping you if you're code isn't formatted properly...they'll just move on. I strongly recomend if you wanna learn c++, stick around.... there are other books that are great for new-comers like you. Also, there are great tutorials here, you can use to get you started....most importantly....don't give up....it can be frustrating at times.....cheer up mate.

In post #11 add 2 closing curly brackets, }, after line 27 and the code should work. (Adding endls after lines 24 and 25 will make it easier to read for the end user). The code you have will then let you populate the 2 dimenesional array from the keyboard. You would need only a slight modification to populate the array from a file if that's where the information will come from.

Hopefully the code you write at home is indented appropriately and the indentation is lost when posting to the board becuase you have figured out how to use code tags yet.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.