C++心得
C++ Primer Plus 第三章 处理数据
题目:编写一个小程序,要求用户使用一个整数指出自己的身高(单位为英寸),然后将身高转换为英尺和英寸。该程序使用下划线字符来指示输入位置。另外,使用一个 const 符号常量来表示转换因子。
提示
- 1 英寸等于 12 英尺;
- b 为退格字符,输出下划线 _ 之后输出 b 可达到使用下划线字符指示输出位置的效果;
#includeconst int inch_per_feet=12;//const 常量-- 1feet=12inches --1 英尺=12 英寸 (转换因子) int main() { using namespace std; cout << "please enter your height in inches:___bbb";// b 表示为退格字符 int ht_inch; //身高(英尺) cin >> ht_inch; int ht_feet = ht_inch / inch_per_feet;//取商 int rm_inch = ht_inch % inch_per_feet;//取余 cout<< "your height is" << ht_feet << "feet,and" << rm_inch << "inchesn"; return 0; }



