c++ program for determining maximum deflection on a beam

I am new at c++ and I am trying to write a code to determine the maximum deflection at the end of a cantilevered beam. I am given the formula : deflection= (4 W L^3)/(E B H^3) where W is the load weight, L is the beams length, E is the modulus of elasticity, B is the beams base, and H is the beams height. I have the following; if someone can correct me on my errors, I would greatly appreciate it.

// Included Header Files ------------------------------------------------------
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <fstream>
#include <cstdlib>
#include <cstdio>

// Namespace ------------------------------------------------------------------
using namespace std;



// MAIN Function --------------------------------------------------------------
int main(int argc, char *argv[])
{

double W;
double l;
double E;
double b;
double h;



cout << "This program calculates the determines the maximum delfelection on a beam";

cout << "Enter the value for load weight(lbs)";
cin >> W;
cout << "enter value for beam length(ft)";
cin >> l;
cout << "Enter value for modulous of elasticity(lb/ft^2)";
cin >> E;
cout << "Enter value for beam's base(ft)";
cin >> b;
cout << "Enter value for beams height(ft)";
cin >> h;



double y;

y = (4 * W*(l*l*l)) / (E*b*(h*h*h));


return y;

}

What's the problem? Maybe output the result to the screen?
1
2
    y = (4 * W*(l*l*l)) / (E*b*(h*h*h));
    cout << "Max deflection is " << y << endl;
+1 for the comment above..

then

use return 0;
not return y;

and maybe you can use

int main()

only. :)
Last edited on
Topic archived. No new replies allowed.