码迷,mamicode.com
首页 > 编程语言 > 详细

c++ 指针数组,输入4个季度的花费,计算出总花费

时间:2018-10-10 19:14:06      阅读:119      评论:0      收藏:0      [点我收藏+]

标签:names   cpp   char   div   return   exp   ios   pac   turn   

#include <iostream>
#include <array>
#include <string>

const int Seasons = 4;
const char * Snames[4] = { "Spring", "Summer", "Fall", "Winter" };

void fill(double pa[]);
void show(double da[]);

int main() {
	double expenses[4];
	fill(expenses);
	show(expenses);
	return 0;
}

void fill(double pa[]) {
	using namespace std;
	for (int i = 0; i < Seasons; i++) {
		cout << "Enter " << Snames[i] << " expenses: ";
		cin >> pa[i];
	}
}

void show(double da[]) {
	using namespace std;
	double total = 0.0;
	for (int i = 0; i < Seasons; i++) {
		cout << Snames[i] << ": $" << da[i] << endl;
		total += da[i];
	}
	cout << "Total Expenses: $" << total << endl;
}

  

c++ 指针数组,输入4个季度的花费,计算出总花费

标签:names   cpp   char   div   return   exp   ios   pac   turn   

原文地址:https://www.cnblogs.com/ranwuer/p/9768083.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!