C++尺寸大小计算

英文题目(老师给的原版题目):

Hat size=weight in pounds divided by height in inches and all that multiplied by 2.9。
Jacket size(chest in inches)=height times weight divided by 288 and then adjusted by adding 1/8 of an inch for each 10 years over age 30.(Note that the adjustment only takes place after a full 10 years.So,there is no adjustment for ages 30 through 39,but 1/8 of an inch is added for age 40.)
Waist in inches=weight divided by 5.7 and then adjusted by adding 1/10 of an inch for each 2 years over age 28.(Note that the adjustment only takes place after a full 2 years.So,there is no adjustment for age 29,but 1/10 of an inch is added for age 30.)
Use functions for each calculation.Your program should allow the user to repeat this calculation as often as the user wishes.

中文题目(简单翻译了一下):

帽子大小=体重(磅)除以身高(英寸)所有这些乘以2.9。
夹克尺寸(胸围英寸)=身高乘以体重除以288,然后对30岁以上的每10岁增加1/8英寸进行调整。(请注意,调整只在整整10年之后进行。因此,30到39岁的年龄没有调整,但40岁的年龄会增加1/8英寸。)
腰围(英寸)=体重除以5.7,然后对28岁以上的每2岁增加1/10英寸进行调整。(请注意,调整只在整整两年之后进行。因此,29岁的年龄没有调整,但30岁的年龄增加了1/10英寸。)
对每个计算使用函数。您的程序应该允许用户按照自己的意愿重复这个计算。

代码:

#include <iostream>
#include <stdlib.h>
using namespace std;

float HatSize(float Weight,float Height){
    float size,temp;
    temp=Weight/Height;
    size=temp*2.9;
    return size;
}

float JacketSize(float Weight,float Height,int Age){
    float temp,size;
    temp=Height*Weight;
    size=temp/288;
    if(Age<=30){
        return size;
    }
    else{
        int temp1;
        float temp2,temp3;
        temp1=Age-30;
        temp2=temp1/10;
        temp3=temp2/8;
        size+=temp3;
        return size;
    }
}

float WaistSize(float Weight,int Age){
    float size;
    size=Weight/5.7;
    if(Age<=28){
        return size;
    }
    else{
        int temp1;
        float temp2,temp3;
        temp1=Age-28;
        temp2=temp1/2;
        temp3=temp2/10;
        size+=temp3;
        return size;
    }
}

int main() {
    float height,weight,hatsize,jacketsize,waistsize;
    int age;
    char ch;
    do{
        cout<<"请输入身高(英寸):"<<endl;
        cin>>height;
        cout<<"请输入体重(磅):"<<endl;
        cin>>weight;
        cout<<"请输入年龄:"<<endl;
        cin>>age;
        hatsize=HatSize(weight, height);
        jacketsize=JacketSize(weight, height, age);
        waistsize=WaistSize(weight, age);
        cout<<"你的帽子尺寸是:"<<hatsize<<"英寸"<<endl;
        cout<<"你的夹克尺寸是:"<<jacketsize<<"英寸"<<endl;
        cout<<"你的腰围是:"<<waistsize<<"英寸"<<endl;
        cout<<"是否继续查询?(y 或 n)"<<endl;
        cin>>ch;
        if(ch!='y' && ch!='n'){
            cout<<"输入错误,程序退出!"<<endl;
            exit(0);
        }
    }while(ch!='n');
    cout<<"退出成功!"<<endl;
    return 0;
}

比较基础的C++题目,适合初学者。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值