#include using namespace std; double bendingMoment(double x, double w, double l); void prettyPrintDouble(double x){ char tmp[21]; sprintf(tmp, "%10.2lf", x); cout << tmp; return; } int main(){ double x, w, l; double moment; cout << "Enter x (distance of w), w (weight), and l (beam length)" << endl; cin >> x >> w >> l; cout << "x = " << x << ", w = " << w << ", l = " << l << endl; if(w < 0){ cout << "Weight: " << w << " cannot be negative" << endl; } if(l < 0){ cout << "Length l: " << l << " cannot be negative" << endl; } if(l < x){ cout << "Length l : " << l << " cannot be less than x: " << x << endl; } if(x < 0){ cout << "Length x: " << x << " cannot be negative" << endl; } if(!(w < 0 || l < 0 || l < x || x < 0)){ moment = bendingMoment(x, w, l); cout << "The maximum bending moment for distance " << x << " is: " << moment << endl; moment = bendingMoment(0.5 * x, w, l); cout << "The maximum bending moment for distance " << x/2.0 << " is: " << moment << endl; return 0; } else { cerr << "Error in input, Exiting..." << endl; return -1; } } double bendingMoment(double x, double w, double l){ return x * w * (l - x) / l ; }