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