0

I am trying to figure out how to call for a function. I have to be able to enter a load amount and see if it passes three tests. These are the equations given.

Buckling Load:
    Max Load = (0.3*E*area) /  ((length/width) * (length/width))
Compressive stress:
    Max Load = area * maximum compressive strength
Slenderness limits:
    Length/width <= 50

E is the modulus of elasticity (1,700,000 psi), the area is the cross-sectional area in square inches and the maximum compressive strength = 445 psi (Douglas fir). Assume the columns to be used are square and are available in intervals of 2 inches (2x2, 4x4, 6x6, etc.). I have to use a different function for each one! HELP :/

I currently have :

{

    int strength, area, length, width, e, maxLoad, bucklingLoad, compressiveLoad, slenderness;
    float bucklingLoad;
    e = 1700000,
    maxLoad =

    cout << "Jessica's Engineering Company Analysis" ;
    cout << "\n*************************************";

    cout <<"\n\nPlease enter the expected load on the column in pounds: ";
    cin << maxLoad;

    cout << "\nPlease enter the length of the column in inches: ";
    cin << length;

    cout << "\n\n_Beam with wide of 2 inches - " ;
    cout << "\n_Beam with wide of 4 inches - " ;
    cout << "\n_Beam with wide of 6 inches - " ;
    cout << "\n_Beam with wide of 8 inches - " ;

}
Aplet123
  • 33,825
  • 1
  • 29
  • 55
  • 4
    _"... message me or even add me on skype ..."_ - [nope](https://stackoverflow.com/help/how-to-ask). The whole point is that the solution is visible here to help other people. – Useless Mar 31 '20 at 12:21
  • 1
    Now, you're trying to write functions to determine whether the inputs satisfy your tests, right? So what would you expect the functions to look like from outside? What inputs do they need and what type should the result be? – Useless Mar 31 '20 at 12:24
  • The results need to make sure just that they pass, if they fail a test it needs to state that it failed but if it passes, it does not state anything unless all three pass then it needs to state "ok". The function is where I am having the biggest problem. All that I know about functions is that you start with void print_bucklingLoad Since that is the first test run) but I dont really understand how to get further. – Jessica Molton Mar 31 '20 at 12:29
  • 1
    not the problem, but it is good practice (dont have the core guideline reference at hand, but it is there) to declare variables only when you can initialize them, and this plays well together with initializing only one variable per line. Declaring 9 in a single line isnt very readable – 463035818_is_not_an_ai Mar 31 '20 at 12:38
  • So, you don't know how to write a function in the first place? I suggest taking a look at the [book list](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list), because the scope is a little large for a question. You probably want something like `bool isBucklingLoadOK(int length, int width, int area)`. – Useless Mar 31 '20 at 14:38

1 Answers1

0

I'm not going to do the whole thing, and you should absolutely learn C++ properly from a book or other resource, because asking open-ended questions is going to be a really slow, frustrating and inefficient way to figure it out - but I can give you a hint to get started.

Buckling Load:
    Max Load = (0.3*E*area) /  ((length/width) * (length/width))

So we can translate this directly into a function, like

double calcBucklingLoad(int length, int width, int area)
{
    return (0.3*E*area) /  ((length/width) * (length/width));
}

(so long as we first define E somewhere, like

const double E = 1700000;

or something similar. It could be another function parameter if you want to reuse the code for different materials).

Then testing whether the max load is greater than the buckling load is just

bool isBucklingLoadOK(int maxload, int length, int width, int area)
{
    return maxload < calcBucklingLoad(length, width, area);
}
Useless
  • 64,155
  • 6
  • 88
  • 132