程序清单3.1_rhodium.c程序_《C Primer Plus》P32

// rhodium.cpp : 定义控制台应用程序的入口点。
//
/* rhodium.c -- 用金属铑衡量您的的体重 */
/*
    时间:2018年06月02日 21:26:34
    代码:程序清单3.1_rhodium.c程序_《C Primer Plus》P32
    目的:初识浮点小数变量类型 float;基本的数学换算,英镑转换成盎司;
*/
#include "stdafx.h"


int _tmain(int argc, _TCHAR* argv[])
{
    float weight;    /* 用户的体重 */
    float value;    /* 相等重量的铑的价值 */
    /* worth(等值的)/thodium(金属:铑) */
    printf("Are you worth your weight in rhodium?\n");    
    printf("Let's chech it out.\n");    /* chech it out(一探究竟) */
    printf("Please enter your weight in pounds: ");    /* pound(英镑) */
/* 从用户处获取输入 */
    scanf("%f", &weight);
/* 假设铑为每盎司 770 美元 */
/* 14.5833 把常衡制的英镑转换为金衡制的盎司 */
    value = 770 * weight * 14.5833;
    printf("Your weight in rhodium is worth $%.2f.\n", value); /* %.2f(意为保留2位小数)*/
    printf("Your are easily worth that! If rhodium prices drop. \n");
    printf("eat more to maintain your value. \n");
    getchar();
    getchar();

    return 0;
}

/*
    在VS2010中运行结果:
--------------------------------------------------
Are you worth your weight in rhodium?
Let's chech it out.
Please enter your weight in pounds: 150
Your weight in rhodium is worth $1684371.13.
Your are easily worth that! If rhodium prices drop.
eat more to maintain your value.
--------------------------------------------------
译文如下:

你是否值得你在铑上的体重?
让我们来看看它。
请输入你的体重,以磅为单位:150
你的铑重量值为1684371.13美元。
你很容易就是值得的! 如果铑价格下跌。
多吃东西来保持你的价值。
--------------------------------------------------
*/


猜你喜欢

转载自blog.51cto.com/13555061/2123528