Question

INTRODUCTION: USE if statement, loops Torsion occurs when an object is twisted due to an applied...

INTRODUCTION: USE if statement, loops

Torsion occurs when an object is twisted due to an applied torque and is expressed in Pascals (Pa) or psi. Where D is the diameter of the rod in inches, P is the torsion load in pounds, and L is the offset (distance from the edge) in inches, the torsion shear stress is given by:

Ts = 16PL/(piD^3)

ASSIGNMENT:

Write a C program that will first allow the user to enter the diameter of the rod in inches. The program needs to ensure that the diameter of the rod is between 6 and 24 inches; if not, it should print an error message and continue to prompt the user until a value between 6 and 24 is entered. If the value is acceptable, the program should compute the shear stress given torsion loads of 7,500 and 10,000 lbs at offsets of 15, 20, 25, …, 50 inches. Use a while loop to control torsion load (initialize at 7500.0 and increment by 2500.0 to 10,000.0) and a nested for loop to control offset (initialize at 15.0 and increment by 5.0 to 50.0). The rod diameter, torsion load, offset, and shear stress should print to the screen.

Your program output will look like the illustration shown below. Use your PC’s cursor to determine the horizontal and vertical spacing for the output format.

SAMPLE OUTPUT FORMAT:

********************************************

     SHEAR STRESS OF A METALLIC MEMBER

Enter rod diameter in inches: x

Torsion load = 7500.0 lbs

Offset (in)    Shear Stress (psi)

   15.0            xxxxx.x

   20.0            xxxxx.x

    .               .

    .               .

    .               .

   50.0            xxxxx.x

Torsion load = 10000.0 lbs

Offset (in)    Shear Stress (psi)

   15.0            xxxxx.x

   20.0            xxxxx.x

    .               .

    .               .

    .               .

   50.0            xxxxx.x

********************************************

Homework Answers

Answer #1

WE are using while loop to check until the user enters valid input nd if loop to check the daiameter valid or not.

#include <stdio.h>

#include <math.h>
#define pi 3.14
int main()
{
int D,P,L;
   float Ts;
int check =1;
printf(" SHEAR STRESS OF A METALLIC MEMBER\n\n");
   while (check) {
printf("Enter the diameter of the rod in inches \n");
scanf("%d ", &D);
   if((D<=6 )|(D>=24))
   printf("Enter valid diameter between 6 and 24 \n");
else
break;  
}
for( P =7500;P<=10000;P+=2500){//Torsion Load
printf("\n Torsion load = %d lbs \n",P );
printf("Offset(in) \t Shear Stress(psi) \n");
for( L=15;L<=50;L+=5){
Ts = 16*P*L/(pi*D*D*D); //D is the diameter of the rod in inches, P is the torsion load in pounds, and L is the offset
printf(" %d \t\t\t %f \n",L,Ts );
}
}
return 0;
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions