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

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

  2. #17
    Registered User
    Join Date
    Nov 2006
    Posts
    9
    could anybody give me like an example program of how they would go about tackling this problem. then i can see what has been done and how it works with my variables. because im finding it difficult to follow all the advice that has been given. cheers

  3. #18
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Using an array

    array[numResults] = aResult;
    numResults++;
    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.

  4. #19
    Registered User
    Join Date
    Mar 2006
    Posts
    725
    Using an array

    Code:
    if(numResults == MAX_SIZE)
    {
        printf("The Lord hath proclaimed that I shalt accept no more input!\n");
        return;
    }
    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;}

  5. #20
    Registered User
    Join Date
    Nov 2006
    Posts
    9
    ok so iv been trying loads of combos and i think i got it...

    but i cant seem to get the second column of my table right, the values are all wrong. i have checked the maths but cant seem to figure out why. Cheers.

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    
    // Define Variables
    
    struct parameters
    {
    	double max_moment;              
    	double min_moment;              
    	double no_inc;            
    	double inc_diff;          
    	double i;
    	double depth;
    	double breadth;
    	double moment_area;
    	double moment;
    	double stress;
    	struct parameters *next;
    
    };
    
    int main(void)
    {
    
    // Define struct components
    
    	struct parameters parametersvariable, *parameters_ptr;
    	struct parameters *first_ptr, *new_ptr, *previous;
    	struct parameters *list_ptr;  
    		
    	parameters_ptr = &parametersvariable;
        
    	{
    
    // Prompt user to input depth, breadth, min_moment, max_moment and no_inc
    
    		fprintf(stdout, "This program will calculate Max/Min Stress over a range of Applied Moments.\n");
    		fprintf(stdout, "The Results will be displayed in table-form at the end.\n\nLets Begin...");
    		fprintf(stdout, "\n\n1. Enter the value for Depth of the Beam: [m]:  ");
    			fscanf(stdin, "%lf", &parameters_ptr->depth);
    		fprintf(stdout, "\n\n2. Enter the value for Breadth of the beam [m]:  ");
    			fscanf(stdin, "%lf", &parameters_ptr->breadth);
    		fprintf(stdout, "\n\n3. Enter the value of the Minimum Applied Moment [Nm]:  ");
    			fscanf(stdin, "%lf", &parameters_ptr->min_moment);
    		fprintf(stdout, "\n\n4. Enter the value of the Maximum Applied Moment [Nm]:  ");
    			fscanf(stdin, "%lf", &parameters_ptr->max_moment);
    		fprintf(stdout, "\n\n5. Enter the Number of Increments between the Min and Max Applied Moments:  ");
    			fscanf(stdin, "%lf", &parameters_ptr->no_inc);
            
    // Calculate the difference between each increment
    
    		parameters_ptr->inc_diff = (parameters_ptr->max_moment-parameters_ptr->min_moment)/parameters_ptr->no_inc;
            parameters_ptr->moment_area  = (parameters_ptr->breadth * (parameters_ptr->depth * parameters_ptr->depth * parameters_ptr->depth)) / 12;
    
    // Work out the values of applied moment using a loop, counter and put in a linked list
    
    		first_ptr = NULL;
    		for(parameters_ptr->i=0; parameters_ptr->i<parameters_ptr->no_inc;parameters_ptr->i++)    
    		{
    			new_ptr = (struct parameters *)malloc(sizeof(struct parameters));
    			if (first_ptr != NULL)
    				previous->next = new_ptr;
    			else
    				first_ptr = new_ptr;
    			new_ptr->next = NULL;
    			
    			new_ptr->moment = parameters_ptr->min_moment + (parameters_ptr->i * parameters_ptr->inc_diff);              
    			new_ptr->stress = (parameters_ptr->moment * parameters_ptr->depth) / (2 * parameters_ptr->moment_area);
    			
    			previous = new_ptr;
    		}
    
    		fprintf(stdout,"\n\nMoments [Nm]         Max/Min Stress [N/m2]\n");
    		list_ptr = first_ptr;
    		while(list_ptr != NULL)
    		{
    			fprintf(stdout, "\n%.2lf      %.2lf\n", list_ptr->moment, list_ptr->stress);
    			list_ptr = list_ptr->next;  
    		}
    		return(0);
    	}
    }

  6. #21
    Registered User
    Join Date
    Nov 2006
    Posts
    9
    YAY!

    i managed to correct the last part just now... within the while loop (the second equation) was taking a pointer from the wrong moment value. it was nt using the value of moment it had just created. it should have read:

    Code:
    new_ptr->stress = (new_ptr->moment * parameters_ptr->depth) / (2 * parameters_ptr->moment_area);
    where parameters_ptr->moment replaced with new_ptr->moment

    id just like to say thanks to salem and jafet who have helped me greatly, i took your advice i created an array to begin with then with that confidence went on to make my own linked list. now all it needs is for me to sex it up a bit. cheers guys

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, 02:34 PM
  4. left hand opperand??
    By Megatron in forum C++ Programming
    Replies: 8
    Last Post: 03-27-2002, 05:50 PM