2015-10-07 23 views
-1

我很難理解這裏的問題。從我的角度來看,當任何這些條件成立時,循環應該繼續執行。當所有「如果」條件都成立時,應該啓動並終止程序。我究竟做錯了什麼?需要一些建議,這while while循環

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

什麼不行?請閱讀[如何問](http://stackoverflow.com/help/how-to-ask)。從簡單的看,似乎你不初始化一堆變量,然後在條件中使用它們。也許你想要一個'do while'循環。 – TartanLlama

+0

歡迎來到Stack Overflow!這聽起來像你可能需要學習如何使用調試器來遍歷代碼。使用一個好的調試器,您可以逐行執行您的程序,並查看它與您期望的偏離的位置。如果你打算做任何編程,這是一個重要的工具。詳細閱讀:** [如何調試小程序](http://ericlippert.com/2014/03/05/how-to-debug-small-programs/)** – NathanOliver

回答

2

您在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! 
+1

並在'if'上。 –

+0

就是這樣,謝謝! – Jason

+0

@LightnessRacesinOrbit已更新! – ergonaut