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

来源:互联网 发布:qq克隆软件 编辑:程序博客网 时间:2024/06/03 20:04
/* 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;}
0 0