Click here to Skip to main content
15,887,822 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello all,

I would like to find the total value of sales during a specific month by each department and in each stores?

I'm having hard time to get total sale value for specific month by each department and in each stores.
Can Someone please help me in this matter

Thank you for taking the time to help.


Here's my code

C++
#include <iostream>
//defining the following global variables
#define NUM_DEPTS 2
#define NUM_STORES 2
#define NUM_MONTHS 12


using namespace std;

//Description: Creating a function to calculate and print the total value of sales
//during a specific month by each department and in each store.
//Pre-condition: We need two parameters array sale, and month. 
//Post-condition: After calling the function inside the main we get the total value of sales 

void  sales(float sale[][NUM_STORES][NUM_MONTHS],int Month);

//Description: Main function where program begins
int main(){
	int Month;
	//Creating three dimensional array of float-point type 
	float sale[NUM_DEPTS][NUM_STORES][NUM_MONTHS] =
	{ 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0, 2.1, 2.2,
	2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 2.8, 2.9, 3.0, 3.1, 3.2,
	3.1, 3.2, 3.3, 3.4, 3.5, 3.6, 3.7, 3.8, 3.9, 4.0, 4.1, 4.2,
	2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 2.8, 2.9, 3.0, 3.1, 3.2,
	};

	system("pause");
	return 0;
}


void  sales(int sale[][NUM_STORES][NUM_MONTHS], int Month){

	int sum = 0;
	
	//creating Three for loop to get the total value of sale 
	for (int i = 0; i < NUM_DEPTS; i++){

		for (int j = 0; j < NUM_STORES; j++){

			for (int k = 0; k < NUM_MONTHS; k++){
				sale[i][j][k];

				cout << "The total sales value " << sale[i][j][k] << endl;


			}
		}
	}


}
Posted
Updated 31-Jan-16 8:38am
v5
Comments
PIEBALDconsult 31-Jan-16 14:45pm    
Gee, wouldn't a database offer a significant benefit here?
Member 12297158 31-Jan-16 16:17pm    
would you please help if you have any idea to get total value of sales
Thank you for your time.
nv3 31-Jan-16 18:19pm    
It's homework and it's easy. Here is a hint: Where in your code are you adding the values up? And are you printing the sum or just the 48 values? In which loop would you have to place your print statement if you wanted to print only the 12 sums? How should you nest your loops, so that the print loop becomes the outer one?

1 solution

The answer looks so easy in your loop:
C++
sum += sale[i][j][month]; //only use the montth
cout << "add sales value " << sale[i][j][month] << endl;

But think about some better solution with structs or classes. As some data structure:
C++
struct {
  int department;
  int stores;
  int sales;
} MONTH;


it helps to organize and clearify data
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900