我想创建一个C++程序,它可以计算3年内销售的东西的数量。循环和二维数组的C++
我想用一个2维数组和一个循环(对于要求实践问题)做
,但不知何故,我不能让我的愿望的结果。计算和存储中有一些错误。你能帮我找出错误吗?
#include <iostream>
#include <string>
#include <array>
using namespace std;
int main(){
int quantity[3][12];
int sum[3];
int *p;
p=sum;
int total;
int year=0;
string months[12]={
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"Octorber",
"November",
"December"
};
for (int i=0; i<12; i++) {
cout<<"Enter the quantity sold in "<<months[i]<<endl;
cin>>quantity[year][i];
if(i==11&&year<3){
year++;
i=-1;
}
}
year=0;
for (int i=0; i<12; i++) {
sum[year]+=quantity[year][i];
if (i==11&&year<3) {
i=(-1);
year++;
}
}
year=0;
for (int i=0; i<3; i++) {
cout<<"the information for year "<<(i+1)<<" is " <<endl;
for (int i1=0; i1<12; i1++) {
cout<<quantity[year][i1]<<endl;
}
cout<<"the sum of the "<< (i+1)<< " year: "<<sum[year]<<endl;
total+=sum[year];
}
cout<<"the total amount sold in three year is "<<total<<endl;
return 0;
}
*计算和存储中存在一些错误。*尚不清楚。指定确切的问题。 – 2014-09-19 04:19:17