c++ 指针数组,输入4个季度的花费,计算出总花费
Posted ranwuer
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c++ 指针数组,输入4个季度的花费,计算出总花费相关的知识,希望对你有一定的参考价值。
#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个季度的花费,计算出总花费的主要内容,如果未能解决你的问题,请参考以下文章