0
点赞
收藏
分享

微信扫一扫

总之就写的很怪

墨春 2022-05-02 阅读 62
c++

         最近在自学C++,做到个题目,要求要有二维数组,要有char*,求三年的销售情况,和总的销售量。是按着需求在写但是却也写的奇怪。     

#include<iostream>
#include<vector>
using namespace std;
const int m = 4;
const int n = 12;
int main()
{
    vector<vector<int> >num(m, vector<int>(n));//定义二维数组为4*12;
    const char* month[n] =
    {
        "junuary","february","march","april","may","june","july","august","september","october","novenber","december"
    };
    cout << "请输入第一年各个月的销量:\n";
    int i = 0;
    while (i < 12)
    {
        cin >> num[1][i];
        //cout<<num[1][i]<<" ";
        i++;
    }
    cout << endl;
    cout << "请输入第二年各个月的销量:\n";
    int j = 0;
    while (j < 12)
    {
        cin >> num[2][j];
        //cout<<num[2][j]<<" ";
        j++;
    }
    cout << endl;
    cout << "请输入第三年各个月的销量:\n";
    int k = 0;
    while (k < 12)
    {
        cin >> num[3][k];
        //cout<<num[3][k]<<" ";
        k++;
    }
    cout << "这三年的销售情况如下:\n\n";
    for (int l = 0; l < 12; l++)
    {
        cout << month[l] << " ";
    }
    cout << endl;
    for (int x = 0; x < 12; x++)
    {
        cout << num[1][x] << " ";
    }
    cout << endl;
    for (int x = 0; x < 12; x++)
    {
        cout << num[2][x] << " ";
    }
    cout << endl;
    for (int x = 0; x < 12; x++)
    {
        cout << num[2][x] << " ";
    }
    int sum = 0;
    for (int k = 0; k < n; k++)
    {
        sum += num[1][k] + num[2][k] + num[3][k];
    }
    cout << "这十二个月的总销售量为:" << sum;
    return 0;
    cout << endl;
    return 0;

}

举报

相关推荐

0 条评论