问题:
解答:
#include <iostream>
using namespace std;
#define MONTHSCOUNT 12
int main()
{
string months[MONTHSCOUNT] = { "January","February","March","April","May","June",
"July","August","September","October","November","December" };
int sales[MONTHSCOUNT] = { 0 };
int sum = 0;
for (int i = 0; i < MONTHSCOUNT; i++)
{
cout << "请输入第" << i + 1 << "月的图书销量:";
cin >> sales[i];
sum += sales[i];
}
for (int i = 0; i < MONTHSCOUNT; i++)
{
cout << months[i] << "的销量为:" << sales[i] << endl;
}
cout << "这一年的总销量为:" << sum << endl;
return 0;
}
运行结果:
考查点:
- 循环
2024年8月25日20:02:52