c语言中身高测试,测身高的C语言程序.doc

此文档收集于网络,如有侵权,请联系网站删除

测量身高C语言程序:

主程序:

// header file

#include // define readonly variable

const char* const ERR_STRING = "您输入的字符有误,请重新";

const char* const INFO_STRING = "*******************************************************";

// will call this function when input have error

void PrintErr(void)

{

printf(ERR_STRING);

while(getchar()!=\n);

}

// get a lower char

char 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 error

int 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 value

double GetDouble(const char* str)

{

double d;

for(puts(str); scanf("%lf",&d)!=1; puts(str+2))

PrintErr();

return d;

}

// stature test

void 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 function

int 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

此文档仅供学习与交流

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值