1. 程式人生 > >C++專案參考解答:胖子不想說體重

C++專案參考解答:胖子不想說體重

【專案 - 胖子不想說體重】
  成年男性的標準體重公式為:
  

(kg)=(cm)100
  超標準體重20%為超重,比標準體重輕20%為超輕。請編寫C++程式,輸入身高和體重,完成下面的任務:
  (1)計算並輸出標準體重。
  (2)計算出標準體重,當超重時,請給出提示。
  (3)計算出標準體重,當超重時給出提示,不超重時也給提示。
  (4)計算出標準體重,輸出體重狀態(正常/超重/超輕)
  除錯完程式,請釋出博文,作為上機報告。

【參考解答】
(1)計算並輸出標準體重。

#include<iostream>
#include<cmath>
using namespace std; int main( ) { int height, stWeight; cout<<"請輸入身高: "; cin>>height; stWeight=height-100; cout<<"標準體重為: "<<stWeight<<endl;1 return 0; }

(2)計算出標準體重,當超重時,請給出提示。

#include<iostream>
#include<cmath>
using namespace std;
int
main( ) { int height, weight, stWeight; cout<<"請輸入身高和體重: "; cin>>height>>weight; stWeight=height-100; if(weight>stWeight*1.2) { cout<<"你超重了! "<<endl; } return 0; }

(3)計算出標準體重,當超重時給出提示,不超重時也給提示。

#include<iostream>
#include<cmath>
using namespace std; int main( ) { int height, weight, stWeight; cout<<"請輸入身高和體重: "; cin>>height>>weight; stWeight=height-100; if(weight>stWeight*1.2) { cout<<"你超重了! "<<endl; } else { cout<<"好棒,健康體重! "<<endl; } return 0; }

(4)計算出標準體重,輸出體重狀態(正常/超重/超輕)

#include<iostream>
#include<cmath>
using namespace std;
int main( )
{
    int height, weight, stWeight;
    cout<<"請輸入身高和體重: ";
    cin>>height>>weight;
    stWeight=height-100;
    if(weight>stWeight*1.2)
    {
        cout<<"你超重了! "<<endl;
    }
    else if(weight<stWeight*0.8)
    {
        cout<<"親,試著多吃點! "<<endl;
    }
    else
    {
        cout<<"好棒,健康體重! "<<endl;
    }
    return 0;
}