我在这里难以理解这个问题。从我的角度看,当任何这些条件成立时,循环应该继续执行。当所有的"如果"条件是真的,应该启动并终止程序。我做错了什么?
double height ;
double width ;
double load ;
double buckle_threshold ;
double area ;
double compress_threshold ;
double slenderness_value ;
const int slenderness_limit = 50 ;
const int E = 1700000 ;
const int stress = 1450 ;
const int inches = 12 ;
cout << "Enter column height in feet: " ;
cin >> height ;
cout << "Enter expected load in pounds: " ;
cin >> load ;
while ( load > buckle_threshold || load > compress_threshold || slenderness_value > slenderness_limit );
{
cout << "Enter column width in inches: " ;
cin >> width ;
slenderness_value = (height/width)*(inches) ;
area = width*width ;
buckle_threshold = (.3*E*area)/(pow((height/width),2)) ;
compress_threshold = area*stress ;
if (load <= buckle_threshold && load <= compress_threshold && slenderness_value <= slenderness_limit );
{
cout << "Compress Threshold = " << compress_threshold << endl ;
cout << "Buckle Threshold = " << buckle_threshold << endl ;
cout << "Column is safe." ;
return 0;
}
cout << "Compress Threshold = " << compress_threshold << endl ;
cout << "Buckle Threshold = " <<buckle_threshold << endl ;
cout << "Column is unsafe." << endl ;
}
return 0;
答案 0 :(得分:1)
while / if循环上有分号。删除它:
while ( load > buckle_threshold || load > compress_threshold
|| slenderness_value > slenderness_limit ); <--- Right there!
if (load <= buckle_threshold && load <= compress_threshold
&& slenderness_value <= slenderness_limit ); <--- Here too!