第17周上机实践项目3——胖子伤不起

问题及代码

/*
 * Copyright (c) 2014, 烟台大学计算机学院
 * All rights reserved.
 * 文件名称:test.cpp
 * 作    者:辛彬
 * 完成日期:2014年 12 月 20 日
 * 版 本 号:v1.0
 *
 * 问题描述: 用结构体输出一个人的体重情况。
 * 输入描述:必要信息。
 * 程序输出:结果;
 */
#include <iostream>
using namespace std;
struct people
{
    char name[10];
    int sex;
    double high;
    double weight;
};
int main()
{
    people people;
    while(people.name[0]!='0')
    {
        cout<<"请输入姓名、性别(1代表男性,2代表女性)、身高(cm)和体重(按0结束):"<<endl;
        cin>>people.name>>people.sex>>people.high>>people.weight;
        double stweight;
        if(people.sex==1)
        {
            stweight=(people.high-80)*0.7;
            if(people.weight>1.2*stweight)
                cout<<people.name<<"先生,你已经很胖了,要减肥了!"<<endl<<endl;
            else if(people.weight<0.8*stweight)
                cout<<people.name<<"先生,你太瘦了!"<<endl<<endl;
            else if(people.weight>1.1*stweight)
                cout<<people.name<<"先生,你有点胖。"<<endl<<endl;
            else if(people.weight<0.9*stweight)
                cout<<people.name<<"先生,你有点瘦。"<<endl<<endl;
            else
                cout<<people.name<<"先生,你的体重正常,恭喜!"<<endl<<endl;
        }
        if(people.sex==2)
        {
            stweight=(people.high-70)*0.6;
            if(people.weight>1.2*stweight)
                cout<<people.name<<"小姐,你已经很胖了,要减肥了!"<<endl<<endl;
            else if(people.weight<0.8*stweight)
                cout<<people.name<<"小姐,你太瘦了!"<<endl<<endl;
            else if(people.weight>1.1*stweight)
                cout<<people.name<<"小姐,你有点胖。"<<endl<<endl;
            else if(people.weight<0.9*stweight)
                cout<<people.name<<"小姐,你有点瘦。"<<endl<<endl;
            else
                cout<<people.name<<"小姐,你的体重正常,恭喜!"<<endl<<endl;
        }
    }
    return 0;
}


运行结果: 第17周上机实践项目3——胖子伤不起_第1张图片

你可能感兴趣的:(编程,C++,计算机,cpp,结构)