### Multidimensional Arrays

I have an assignment that requires multidimensional arrays. I have succesfully inputted the values, but I am not sure how to do the rest of the processes with the array.

The assignment is to take in sales for 4 stores for 3 months. I then need to sum the sales for each store. They would like for me to identify the highest sum, and divide the other sums by it. That number represents how many "*" to output on a bar graph.

So far, I've been doing the addition and division manually. Any help? Also my function I am trying to pass Quarter_sales is not working properly.

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869`` ``````//Setup standard environment #include #include #include using namespace std; void title () { // Output program name cout << endl; cout<< " Store Bar Chart- Store Comparison " <>sales[i][j]; } } return sales[12][12]; } int main() { title(); int i,j,k,l,m; int sales[12][12]; int total1,total2,total3,total4,output1,output2,output3,output4; const int STORE=5; const int STORE1=2; const int MONTHS=4; cout<< "Input store sales for the quarter by months. Negative values are not allowed."<
I think this would be the correct code

 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061`` ``````//Setup standard environment #include #include #include using namespace std; #define STORE 5 #define STORE1 2 #define MONTHS 4 void title () { // Output program name cout << endl; cout<< " Store Bar Chart- Store Comparison " <> sales[i][j]; cout << "\n"; } } // you need to return the array variable name, not data from the array return sales; } int main() { // setup some variables int sales[12][12]; int total1, total2, total3, total4, output1, output2, output3, output4; // display the intro title(); cout << "Input store sales for the quarter by months. Negative values are not allowed." << "\n\n"; cout << "Please enter store sales in whole dollar values" << "\n\n\n"; sales = Quarter_sales(); // and do some math total1 = sales[0][0] + sales[0][1] + sales[0][2]; total2 = sales[1][0] + sales[1][1] + sales[1][2]; total3 = sales[2][0] + sales[2][1] + sales[2][2]; total4 = sales[3][0] + sales[3][1] + sales[3][2]; output1 = total1 / 2000; output2 = total2 / 2000; output3 = total3 / 2000; output4 = total4 / 2000; return 0; }``````

That should run, but I'm away from a compiler right now so I can't really test it.

And for returning arrays, you can't return like this:

 `` `` ``return sales[0][0];``

Thats for returning the data stored in the array at section (0, 0);

you need to just return the array without those brackets. You might also want to make sure that the array your filling with the function is the same size as the returned thing.

This will produce an error:

 ``123456`` ``````int returnArray() { int tempArray[5] = {1, 2, 3, 4, 5 }; return tempArray; } int array[2] = returnArray();``````

This works though:
 ``123456`` ``````int returnArray() { int tempArray[] = {1, 2, 3, 4, 5 }; return tempArray; } int array[] = returnArray();``````
Last edited on
Topic archived. No new replies allowed.