发布时间:2019-07-29 16:41:23
当P小于1.00时,体形太瘦"Thin"; 当P大于等于1.00且小于1.15时,体形为有点瘦"Little thin"; 当P大于等于1.15且小于1.45时,体形为标准"Stanard"; 当P大于等于1.45且小于1.60时,体形为有点胖"Little fat"; 当P大于等于1.60时,体形为太胖"Too fat"。
我的代码:
#include<bits/stdc++.h>using namespace std;int main(void){double a,b,p;cin >> a >> b;p = a/b*b*b*100000;if(p < 1.00)cout <<"thin";if(1.00 <= p < 1.15)cout << "little thin";if(1.15 <= p < 1.45)cout << "stanard";if(1.45 <= p <1.60)cout << "little fat";if(1.60 <= p)cout << "fat";return 0;}
输出结果:
60 160
little thinstanardlittle fatfat
--------------------------------
Process exited after 3.067 seconds with return value 0
请按任意键继续. . .
C++的表达式,与数学表达式是不一样的
你的
if(1.00 <= p < 1.15) 这个在C++语法正确,但结果完全不是你要的
正确的
if(1.00 <= p && p< 1.15)
(具体原理你可以参考下你教材上逻辑运算部分)