gpt4 book ai didi

c++ - 二维数组和嵌套循环

转载 作者:行者123 更新时间:2023-11-30 04:11:30 25 4
gpt4 key购买 nike

<分区>

我正在尝试使用二维数组和嵌套循环打印出三年中 12 个月的销售额。我很困惑。有人可以告诉我使用这些方法我的代码做错了什么。我不想要其他选择。

#include "stdafx.h"
#include <iostream>
#include <string>

using namespace std;
int x = 0;
int v = 0;
int y = 0;
int sum = 0;
const int year = 3;
const int month = 12;

int _tmain(int argc, _TCHAR* argv[])
{
int sales[year][month];
char * date[12] = {"january", "february", "march", "april", "may", "june", "july", "august", "september", "october", "november", "december"};
for(int z = 0; z < 3; z++)
{
{
cin >> v;
sales * year[z] = v;
}

for(int x = 0; x < 12; x++)
{
cout << "Please enter the sales for month " << date[x] << ":\n";
cin >> y;
sales * month[x] = y;
sum += y;
}
}
cout << "There are the sales of the c++ crook: \n";

cout << sales[3][12] << endl;
//cout << "Month 1 = " << year[0] << " " << month[0] << endl;
//cout << "Month 2 = " << year[0] << " " << month[1] << endl;
//cout << "Month 3 = " << year[0] << " " << month[2] << endl;
//cout << "Month 4 = " << year[0] << " " << month[3] << endl;
//cout << "Month 5 = " << year[0] << " " << month[4] << endl;
//cout << "Month 6 = " << year[0] << " " << month[5] << endl;
//cout << "Month 7 = " << year[0] << " " << month[6] << endl;
//cout << "Month 8 = " << year[0] << " " << month[7] << endl;
//cout << "Month 9 = " << year[0] << " " << month[8] << endl;
//cout << "Month 10 = " << year[0] << " " << month[9] << endl;
//cout << "Month 11 = " << year[0] << " " << month[10] << endl;
//cout << "Month 12 = " << year[0] << " " << month[11] << endl;

//cout << "Month 1 = " << year[1] << " " << month[0] << endl;
//cout << "Month 2 = " << year[1] << " " << month[1] << endl;
//cout << "Month 3 = " << year[1] << " " << month[2] << endl;
//cout << "Month 4 = " << year[1] << " " << month[3] << endl;
//cout << "Month 5 = " << year[1] << " " << month[4] << endl;
//cout << "Month 6 = " << year[1] << " " << month[5] << endl;
//cout << "Month 7 = " << year[1] << " " << month[6] << endl;
//cout << "Month 8 = " << year[1] << " " << month[7] << endl;
//cout << "Month 9 = " << year[1] << " " << month[8] << endl;
//cout << "Month 10 = " << year[1] << " " << month[9] << endl;
//cout << "Month 11 = " << year[1] << " " << month[10] << endl;
//cout << "Month 12 = " << year[1] << " " << month[11] << endl;
//cout << "The annual sales for c++ crook is: " << sum << " ;]";
cin.get();
cin.get();


return 0;
}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com