Help! I am writing this code and it is kicking my butt! I have reread the book and made every change I can think of...I am LOST! Any advise would be greatly appreciated!
This is the assignment:
Write a MAIN function and the following funcations to compute the stress and strain in a steel rod of diameter D (inches) and length L (inches) subject to the compress loads P of 10,000 to 1,000,000 pounds in increments of 100,000 pounds. The modulus of elasticity E for steel is 30 x 10 to the 6th power.
A function to compute the stress from the formulas:
stress f = P/A
Where A = PI Dsquared/4.0
A funcation to compute the strain from the formulas:
elondated or shortened length (delta)L=fL/E
strain e = (delta)L/L =f/e
A funcation to output the stress and strain at differant loads of P
Main
*
*****************************
* * *
calculate stress calculate strain output
The functions should call each other as shown in the chart above.
Here is the code I wrote and am having problems with:
Code:
#include<stdio.h>
#include <math.h>
float compute_stress();
float compute_strain();
float output_results();
int main( )
{
float compute_stress (float stress, int p);
float compute_strain (float strain);
void output_results(float stress, float strain, int p);
return 0;
}
float compute_stress()
{
const float PI = 3.141593;
float stress, diam , area;
printf("Enter diameter: \n");
scanf_s("%d", &diam);
area=(PI * (diam *diam ))/4;
{
int p;
for(p=10000; p<=100000000; p= p+100000)
{
stress = p/area;
return stress;
}
}
}
float compute_strain(float stress)
{
const float e=30000000;
float strain;
strain = stress/e;
return strain;
}
void output_results (int p, float stress, float strain)
{
printf("Compression Load = %f lbs. Stress = %f Strain = %f", p, stress, strain);
return;
}