如何获得每个部门和每个商店在特定月份的销售总价值? [英] How to get the total value of sales during a specific month by each department and in each stores ?

查看:64
本文介绍了如何获得每个部门和每个商店在特定月份的销售总价值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我想查找每个部门和每个商店在特定月份的销售总价值?



我很难在每个部门和每个商店获得特定月份的总销售价值。

有人可以帮我解决这个问题



感谢您抽出宝贵时间提供帮助。





这是我的代码



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

#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;


			}
		}
	}


}

推荐答案

答案在你的循环中看起来很容易:

The answer looks so easy in your loop:
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:

struct {
  int department;
  int stores;
  int sales;
} MONTH;





它有助于整理和清理数据



it helps to organize and clearify data


这篇关于如何获得每个部门和每个商店在特定月份的销售总价值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆