本文主要是介绍【C++ Primer Plus习题】5.5,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
问题:
解答:
#include <iostream>
using namespace std;#define MONTHSCOUNT 12int 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
这篇关于【C++ Primer Plus习题】5.5的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!