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; }
相关文章推荐
- c++ primer plus 第七章《编程题7.13.7》
- C++学习笔记(一)函数模板与类模板
- c++ primer plus 第七章《编程题7.13.1-求两个数的调和平均数》
- c++ primer plus 第七章《编程题7.13.9》
- 修改C中const修饰的变量
- c++ primer plus 第六章《编程题6.11.2》
- Effective C++ 条款5 了解C++默默编写并调用哪些函数
- C++:编译器合成默认构造函数和复制控制成员的条件
- c++ primer plus 第五章《编程题5.9.4》
- C++笔记之常量与如何赋值
- 使用C语言实现最小生成树求解的简单方法
- #include<bits/stdc++.h>这个头文件的使用
- 【C++对象模型】使用gcc、clang和VC++显示C++类的内存布局
- C/C++ 中的特殊关键字:volatile, register, restrict, __attribute__
- C++ 小记 vector 容器(一)
- C/C++代码静态检查工具Cppcheck在VS2013开发环境中的安装配置和使用
- 求任意一个数字的阶乘《C语言版》
- 算法 - 乞讨n中位数(C++)
- C++ Web Programming
- c++ primer plus 第九章《编程题9.6.2》