求助:用C++编写男女标准体重

来源:百度知道 编辑:UC知道 时间:2024/09/28 14:41:54
题目:
先让用户选择性别,其中m代表男性、f代表女性,
再用公式:
(男)标准体重=身高-105cm
(女)标准体重=身高-100cm
再输出该标准体重

求助阿,我是个刚学c++不久的大一新生,对于if else语句一窍不通……望多多指教,希望能有具体的解释,谢谢!

#include <iostream>
using namespace std;

int main()
{
char cSex;
do
{
cout<<"Sex (m male, f female): ";
cin>>cSex;
} while (cSex != 'm' && cSex != 'f');

int nHeight;
do
{
cout<<"Height(cm): ";
cin>>nHeight;
} while (nHeight<=0);

cout<<"Weight: ";
if (cSex == 'm')
cout<<nHeight-105<<endl;
else
cout<<nHeight-100<<endl;

return 0;
}