大学c语言身高测量程序,测身高的C语言程序.doc

62e50291a81fc54b507f33cb80033297.gif 测身高的C语言程序.doc

(2页)

0012a6417f539c13db5758e1233f7309.gif

本资源提供全文预览,点击全文预览即可全文预览,如果喜欢文档就下载吧,查找使用更方便哦!

14.90 积分

此文档收集于网络,如有侵权,请联系网站删除测量身高C语言程序:主程序:// header file#include // define readonly variableconst char* const ERR_STRING = "您输入的字符有误,请重新";const char* const INFO_STRING = "*******************************************************";// will call this function when input have errorvoid PrintErr(void){    printf(ERR_STRING);    while(getchar()!='\n');}// get a lower charchar GetLowerChar(const char* str){    char c;    puts(str); // output infomation for input    scanf(" %c",&c);    return (c>='A' && c<='Z')?c+32:c;// translate to lower}// Get a char choose in a & b.// other character will make errorint LoopInputChar(const char* str, char a = 'y', char b = 'n'){    char a1 = GetLowerChar(str);    for(; a1!=a && a1!=b; a1 = GetLowerChar(str+2))        PrintErr();    return a1;}// Get a double-type valuedouble GetDouble(const char* str){    double d;    for(puts(str); scanf("%lf",&d)!=1; puts(str+2))        PrintErr();    return d;}// stature testvoid StatureTest(){    char c, ys;    double fu,mu,wo,wo2;    fu = GetDouble("请输入您的父亲身高:");    mu = GetDouble("请输入您的母亲身高:");    {        // input gender        c = LoopInputChar("请输入您的性别,男生M,女生F:", 'm', 'f');        if(c == 'm')            wo = (fu+mu)*0.54;        else            wo = (fu*0.923+mu)/2;        wo2 = wo;    }    // input other infomations    c = LoopInputChar("请回答:您平时喜欢锻炼吗?(y/n):");    ys = LoopInputChar("请回答:您平时饮食规律吗?(y/n):");    if(c == 'y') // check the answer and calculate    {        wo2 += wo*0.02;        if(ys =='y') wo2 += wo*0.015;    }    else if(ys =='y')    {        wo2 += wo*0.015;    }    // output    printf("您的未来身高是%.2lf米!\n",wo2);    puts(INFO_STRING);    return ;}// main functionint main(void){    // output infomation about the test    puts("现在将为您测试一下未来身高,请相信它的科学性!");    puts(INFO_STRING);    do // loop input test    {        StatureTest();        // is exit program    }while(LoopInputChar("请回答:您要退出吗?(y/n):")=='n');    return 0; // must be null此文档仅供学习与交流 关 键 词: c语言 程序 身高

524d6daf746efaa52c3c71bbfe7ba172.gif  天天文库所有资源均是用户自行上传分享,仅供网友学习交流,未经上传用户书面授权,请勿作他用。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值