# Thread: Desperate !! In need of a helping hand...

1. ## Desperate !! In need of a helping hand...

Desperate !! Stuck on a simple C task...
--------------------------------------------------------------------------------

hey all, as part of my computing module i have been asked to create a program that will promp the user for the following:

depth_beam /* i.e fprintf etc "enter value of beam" then fscanf %lf depth_beam*/
min_moment
max_moment
number_increments /*between minimum and maximum moments*/

then calculate bending stress using a loop controlled by relevant input data ^ and should store values of moment maximum and minimum stress in a linked list.

after completing calculations it is to write the values from the linked list to the screen as a table:

depth of beam:
minimum applied moment:
maximum applied moment
number of increments.

as a guide iv included the program that i used on the previous question which was to calculate max and min tensile stresses:

Code:
```#include <stdio.h>
int main(void)

{
double tensile_min;
double tensile_max;
double bending_moment;
double moment_area;
double depth_beam;

fprintf(stdout, "Enter the magnitude of the Applied Bending Moment (Nm):");
fscanf(stdin, "%lf", &bending_moment);
fprintf(stdout, "Enter the Breadth of the beam (m):");
fprintf(stdout, "Enter the Depth of the beam (m):");
fscanf(stdin, "%lf", &depth_beam);

moment_area = (breadth_beam * depth_beam * depth_beam * depth_beam) / 12;
tensile_min = ((0-bending_moment) * depth_beam) / (moment_area*2);
tensile_max = (bending_moment * depth_beam) / (moment_area * 2);

fprintf(stdout,"\n\nThe Second Moment of Area for this particular beam is: %.2lf m4\n", moment_area);
fprintf(stdout,"With a Minimun Tensile Stress of %.3lf N/m2\n", tensile_min);
fprintf(stdout,"And a Maximum Tensile Stress of %.3lf N/m2\n", tensile_max);

return(0);
}```
cheers in advance, any help would be greatly apreciated, i have got a really unhelpful tutor who wont explain beyond his set of notes (which are extremely poor and unthought-out

James

2. OK, so which bit is confusing you?

I guess it's not the "read values from the user", since your other program does that OK?

Is it the loop from min_moment to max_moment?
- Can you do this and just print the results to the screen (ignoring the list bit)

Though I don't see why you need a whole list just to store a min and a max....

3. hey man thanks for replying so quick.

basically, i dont know how to incorporate a loop and a linked list to the program posted! the list is supposed to store maximum, minimum stresses and the value of the moment. dont know what way would be the best way to structure it, do you have any idea? a template perhaps?

james

4. Something like
Code:
```for ( i = min ; i < max ; i += (max-min)/numIncrements ) {
}```
I guess inside that, you put the example you posted to perform a single calculation.

5. Sorry to ask a "stupid" question but what is fprintf and can someone also type a prototype of it like if (conditional) thanks.
Statment;

6. Search with google: 'man fprintf'.

7. Erm, KoG Metalgod, will you please stop hijacking other peoples threads with your own off-topic questions.

8. hey salem, thanks in abundance for all your help.

i need to make a linked list that stores all the values of stress, calculated for each value of applied moment, incorporating the number of increments...

so lets say minimum stress works out to be 100 Nm and max is 500 Nm and your number of increments is 5 then you'd need to store values for 100, 200, 300, 400, and 500 Nm

so, im going to have to define number_increments, as well as the others on my first program, any suggestions

moment=minimum_moment
increment =
while (moment < = maximum moment)
use existing code to calculate the min and max stress
moment = moment + increment

would this work do u think, then if i can find a way of pointing the answers to a linked list to store value sof stress

9. Start by creating a Node structure, then create your linked list dynamically. Assuming you get number of increments as a parameter, you can determine what values to store at runtime. Further, you will also essentially know how many nodes you will need in your linked list.

10. wooah!! nodes, runtime...

im a beginner and havnt touched on features like that. I just need to get a solution using a loop for amount of increments and a linked list to store the calculated value of max, min stress and applied moments.. cheers anyway

11. might it be easier if i posted the entire Question?

12. Originally Posted by yojimbo2005
wooah!! nodes, runtime...

im a beginner and havnt touched on features like that. I just need to get a solution using a loop for amount of increments and a linked list to store the calculated value of max, min stress and applied moments.. cheers anyway
linked list is nothing but creating the nodes at the run time and storing those values. If your question specifies u to use linled list then u better of look into some topic which actuallu deals which creating a node, how to insert that node on to the list and so on.

ssharish2005

13. Rather than store it in a linked list, try storing it in an array first just to get used to the idea.

Linked lists are a bit on the tricky side to get right.

Though if you're just after max and min, it only needs something like

if ( result > max ) max = result;
if ( result < min ) min = result;
Which you do after each calculation inside your loop.

14. Originally Posted by yojimbo2005
wooah!! nodes, runtime...

im a beginner and havnt touched on features like that. I just need to get a solution using a loop for amount of increments and a linked list to store the calculated value of max, min stress and applied moments.. cheers anyway
You won't be able to do linked lists without nodes, my friend. However, as Salem said, arrays are probably what you're looking for. They're easier to understand and implement (and you avoid the whole Node mish-mash).

15. Actually, if you're not going to do any inserting (except at the end), deleting or complex splicing operations, it's best to use a dynamic array. You allocate some space using malloc() or something. When you run out of space, realloc() some more.

If the assignment specifies that you have to use a list, well you basically have no choice then.

To get the basic code working right, you can take the easy way out and create a fixed size array. You'll have to restrict user input to a certain size though.

Popular pages Recent additions