您的位置:首页 > 编程语言 > C语言/C++

c++ primer plus 第七章《编程题7.13.8a》

2015-08-19 15:43 423 查看
/*
Enter your Spring's expenses: 12.88
Enter your Summer's expenses: q
Invalid value!
Enter your Summer's expenses: 100.90
Enter your Fall's expenses: 3000
Enter your Winter's expenses: 45.88
Spring: 12.88
Summer: 100.9
Fall: 3000
Winter: 45.88
*/
#include <iostream>

using namespace std;

const int Row = 4;
const int Col = 10;
const char Season[Row][Col] = {"Spring", "Summer", "Fall", "Winter"};
void fill_array(double *, const int);
void show_array(double *, const int);

int main() {
double expense[Row];

fill_array(expense, Row);
show_array(expense, Row);
}

void fill_array(double pE[], const int n) {
int i = 0;
while (i < n) {
cout << "Enter your " << Season[i] << "'s expenses: ";
if (!(cin >> pE[i])) {
cin.clear();
while (cin.get() != '\n')
;
cout << "Invalid value!\n";
continue;
}
i++;
}
}

void show_array(double pE[], const int n) {
for (int i = 0; i < n; i++)
cout << Season[i] << ": " << pE[i] << endl;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: