Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Stress and Strain Program

$
0
0
Greetings everyone,

I'm new to the C Language and currently taking a course for it. I've hit an area that I can't seem to figure out though...

Below is my code so far. I don't think the numbers are right for the calculations, but I am able to get the stress and strain to print, but it's only for one calculation. I think my problem lies in the FOR loop since it isn't looping, or appears that way to me.

What I am trying to figure out how to do is get the code to print a list of loads with their associated stress and strain.

If anyone can give me some guidance it will be greatly appreciated.

Thanks.

 
#include <stdio.h>
#include <math.h>
float compute_stress();
float compute_strain(float stress);
void output_results(float stress, float strain);

int main( )
{
	float stress;
	float strain;
	stress = compute_stress();
	strain = compute_strain(stress);
	output_results(stress,strain);
	
	system("PAUSE");
	
	return(0);
}

float compute_stress()
{
	const float pi = 3.141593f;
	float stress;
	float diameter;
	float length;
	float area;
	long int p;
	stress=0;

	printf("\nEnter the diameter of the steel rod in inches: ");
	scanf("%f", &diameter);

	printf("\nEnter the length of the steel rod in inches: ");
	scanf("%f", &length);

	for(p = 10000; p <= 1000000; p += p+100000)
		{
			area = (pi * diameter *diameter) / 4;
			stress = p / area;
		}

	return stress;
}

float compute_strain(float stress)
{
	const float E=30000000;

	float strain;

	strain = stress / E;

	return strain;
}
void output_results (float stress, float strain)
{
printf("\nStress = %f \nStrain = %f\n", stress, strain);
}


Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>