c++入门事例,c++入门教程
#include <iostream> using namespace std; int main() { double height,weight; cout << "请输入您的身高:" << endl; cin >> height; while(1) { if (height <= 0){ cout << "身高输入格式错误,请重新输入您的身高:" << endl; cin >> height; }else{ break; } } cout << "请输入您的体重:" << endl; cin >> weight; while(1) { if (weight <= 0) { cout << "体重输入格式错误,请重新输入您的体重:" << endl; cin >> weight; }else{ break; } } double health; health = weight / (height - 100 ); health = (double)( ( (int) ( (health + 0.005) *100) ) ) / 100; cout << health << endl; if (health > 1.2){ cout << "您偏胖!" << endl; }else if (height < 0.8){ cout << "您偏瘦!" << endl; }else{ cout << "恭喜您的身体正常。" << endl; } return 0; }
c++计算成年人的健康状态