简体   繁体   English

需要一些有关此 while 循环的建议

[英]Need some advice with this while loop

I'm having difficulties understanding the problem here.我很难理解这里的问题。 From my perspective it looks like the loop should continue executing when any of these conditions are true.从我的角度来看,当这些条件中的任何一个为真时,循环似乎应该继续执行。 When all of the "if" conditions are true, that should kick in and terminate the program.当所有“if”条件都为真时,应该启动并终止程序。 What am I doing wrong?我究竟做错了什么?

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;

You have a semicolon on the while/if loop.你在 while/if 循环上有一个分号。 Remove it:去掉它:

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!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM