(提前声明,以下皆为我自己做题时所记录,方便以后查看,当然也希望大家一起来观看并指出我的错误。)
#include<iostream>
#include<string>
using namespace std;
const int nSeasons = 4;
const char* aSnames[4] = { "Spring", "Summer", "Fall", "Winter" };
void fnFill(double* pa);
void fnShow(double* pa);
int main()
{
double aExpenses[nSeasons];
fnFill(aExpenses);
fnShow(aExpenses);
return 0;
}
void fnFill(double* pa)
{
for (int i = 0; i < nSeasons; i++)
{
cout << "Enter " << aSnames[i] << " expenses: ";
cin >> pa[i];
}
}
void fnShow(double* pa)
{
double total = 0.0;
cout << "\nEXPENSES\n";
for (int i = 0; i < nSeasons; i++)
{
cout << aSnames[i] << ": $" << pa[i] << endl;
total += pa[i];
}
cout << "Total Expenses: $" << total << endl;
}