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

This is a discussion on Desperate !! In need of a helping hand... within the C Programming forums, part of the General Programming Boards category; Desperate !! Stuck on a simple C task... -------------------------------------------------------------------------------- hey all, as part of my computing module i have been ...

  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    9

    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*/
    breadth_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:
    breadth 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;
    double breadth_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):");
    fscanf(stdin, "%lf", &breadth_beam);
    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. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,548
    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....
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Nov 2006
    Posts
    9
    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
    Last edited by yojimbo2005; 11-19-2006 at 11:23 AM.

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,548
    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.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Registered User
    Join Date
    Nov 2006
    Posts
    65
    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. #6
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Search with google: 'man fprintf'.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  7. #7
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,548
    Erm, KoG Metalgod, will you please stop hijacking other peoples threads with your own off-topic questions.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  8. #8
    Registered User
    Join Date
    Nov 2006
    Posts
    9
    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


    Read minimum_moment
    Read maximum_moment
    Read number_incremenets

    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
    Last edited by yojimbo2005; 11-20-2006 at 03:51 PM.

  9. #9
    Fear the Reaper...
    Join Date
    Aug 2005
    Location
    Toronto, Ontario, Canada
    Posts
    625
    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.
    Teacher: "You connect with Internet Explorer, but what is your browser? You know, Yahoo, Webcrawler...?" It's great to see the educational system moving in the right direction

  10. #10
    Registered User
    Join Date
    Nov 2006
    Posts
    9
    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. #11
    Registered User
    Join Date
    Nov 2006
    Posts
    9
    might it be easier if i posted the entire Question?

  12. #12
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,682
    Quote 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. #13
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,548
    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.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  14. #14
    Fear the Reaper...
    Join Date
    Aug 2005
    Location
    Toronto, Ontario, Canada
    Posts
    625
    Quote 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).
    Teacher: "You connect with Internet Explorer, but what is your browser? You know, Yahoo, Webcrawler...?" It's great to see the educational system moving in the right direction

  15. #15
    Registered User
    Join Date
    Mar 2006
    Posts
    725
    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.
    Code:
    #include <stdio.h>
    
    void J(char*a){int f,i=0,c='1';for(;a[i]!='0';++i)if(i==81){
    puts(a);return;}for(;c<='9';++c){for(f=0;f<9;++f)if(a[i-i%27+i%9
    /3*3+f/3*9+f%3]==c||a[i%9+f*9]==c||a[i-i%9+f]==c)goto e;a[i]=c;J(a);a[i]
    ='0';e:;}}int main(int c,char**v){int t=0;if(c>1){for(;v[1][
    t];++t);if(t==81){J(v[1]);return 0;}}puts("sudoku [0-9]{81}");return 1;}

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Anyone interested in helping me out again??
    By xMEGANx in forum C++ Programming
    Replies: 19
    Last Post: 10-04-2007, 01:43 AM
  2. Cribbage Game
    By PJYelton in forum Game Programming
    Replies: 14
    Last Post: 04-07-2003, 10:00 AM
  3. what are some other 'life skills' that can go hand in hand with programming
    By Shadow12345 in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 01-17-2003, 01:34 PM
  4. left hand opperand??
    By Megatron in forum C++ Programming
    Replies: 8
    Last Post: 03-27-2002, 04:50 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21