last resort

This is a discussion on last resort within the C Programming forums, part of the General Programming Boards category; i tried everything, i guest is not enough :-) if some one willing to help i appreciated this is the ...

  1. #1
    Registered User
    Join Date
    Nov 2009
    Posts
    15

    last resort

    i tried everything, i guest is not enough :-) if some one willing to help i appreciated
    this is the one of so many trial i have done. but still doesn't work
    Code:
    #include <stdio.h>
    main()
    {
        int a=0, b=0, c=0, d=0, e=0, f=0, g=0, h=0, i=0, j=0, what = 0;
    	
    	
    	c = 10;
    	e = 6;
    	g = 2;
    	j = 1;
    
    	while (what<10 )
    	{
    	
    		if (a == 0,b && c != 0)
    			a = b + c;
    
    			
    		if (b == 0,a && c != 0 || d && e != 0)
    			b = d + e;
    			b = a - c;
    		
    		
    		if (c == 0,e && f != 0 || a && b != 0)
    			c = e + f;
    			c = a - b;
    		
    		
    		if (d == 0,g && h != 0 || b && e != 0)
    			d = g + h;
    			d = b - e;
    		
    		if (e == 0,h && i != 0 || b && d != 0 || c && f != 0)
    			e = h + i;
    			e = c - f;
    			e = b - d;
    		
    		if (f == 0,i && j != 0 || c && e !=0 || f && j != 0)
    			f = i + j;
    			f = c - e;
    		
    		if (g == 0,d && h != 0)
    			g = d - h;
    		
    		if (h == 0,d && g != 0 || e && i !=0)
    			h = e - i;
    			h = d - g;
    		
    		if (i == 0,e && h != 0 || f && j !=0)
    			i = e - h;
    			i = f - j;
    		
    		
    		if (j == 0,f && i != 0)
    			j = f - i;
    		
    		what++;
    		
    
    		printf("\n         %d  \n", a);
    		printf("\n      %d     %d  \n", b, c);
    		printf("\n   %d     %d     %d     \n", d, e, f);
    		printf("\n%d     %d     %d      %d \n", g, h, i, j);
    		
    	}
    		
    		
    			
    
    
    }

  2. #2
    Registered User
    Join Date
    Nov 2009
    Posts
    60
    What is your program supposed to do?

  3. #3
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,302
    Don't give us that "tried everything" nonsense. You've tried everything except actually looking up how to use the various operators etc that you are using - the only thing that would have actually been useful. You've just randomly typed in stuff hoping to hit the correct syntax by accident. You can't program like that. You have to actually learn how to use the stuff that you need to use.

    Every single one of those if-statements probably wont do what you expect. Go and look up how to use the && operator, and learn how to use a statement block so that you can include multiple statements after an if-statement. Learn about when it makes sense to use the comma operator - hint: not in this program.

    Last but not least: How the hell are we supposed to know what your program should do?!?! It might work perfectly if all it's supposed to do is output a pyramid of uninteresting numbers.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  4. #4
    Registered User
    Join Date
    Nov 2009
    Posts
    15
    thanks for the advise, but i did try everything that i know but it seams i don't know enough, the program is a pyramid that the top number is the sum of the 2 numbers below it. but some of the number is known, and can put in various place in the pyramid. and can some one tell me also how to write flow chart for it
    @iMAc i will look at the && operator again, please keep helping me thanks.
    thanks again if u have any other suggestion please don't hesitate.

  5. #5
    Registered User
    Join Date
    Oct 2009
    Location
    While(1)
    Posts
    377
    Quote Originally Posted by juiceceri View Post
    thanks again if u have any other suggestion please don't hesitate.
    Why would any body will hesitate dude to help you out if you write a program which can be read. There are loads of compile time errors there. You are telling us what you want to do. Means a logic but your C/C++ syntax even are not correct at each and every line i think. What iMac is telling try to learn how if statement and operators work. Learn those things and try to improve the code and then post it here

  6. #6
    Registered User
    Join Date
    Nov 2009
    Posts
    15
    it's working if i enter the value for (a,b,e,g,h) but why it's not working if i change the value to (c,e,g,i) why do i have zero, is it because the while loop?
    Code:
    #include <stdio.h>
    main()
    {
        int a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0, i = 0, j = 0 ;
    	char what='?';
    	
    	a = 32;				
    	b = 16;
    	e = 8;
    	g = 4;
    	j = 4;
    
    
    /*	c = 10;
    	e = 6;
    	g = 2;
    	j = 1;
    */
    
    
    
    	         /*printf("\n         %c  \n", a);
    		printf("\n      %c     %c  \n", b, what);
    		printf("\n   %c     %c     %c     \n", what, e, what);
    		printf("\n%c     %c     %c      %c \n", g, what, what, j);*/
    
    	while (!(a&&b&&c&&d&&e&&f&&g&&h&&i&&j))
    	{
    
    // first triangle
    		if(b&&c )
    			a = b + c;
    		if(a&&c )
    			b = a - c;
    		if(a&&b )
    			c = a - b;
    	
    //second triangle
    		if(d&&e )
    			b = d + e;
    		if(b&&e )
    			d = b - e;
    		if(b&&d )
    			e = b - d;
    		
    // third triangle
    		if(e&&f )
    			c = e + f;
    		if(c&&f )
    			e = c - f;
    		if(c&&e )
    			f = c - e;
    		
    // forth triangle
    		if(g&&h )
    			d = g + h;
    		if(d&&h )
    			g = d - h;
    		if(d&&g )
    			h = d - g;
    		
    // fifth triagle
    		if(h&&i )
    			e = h + i;
    		if(e&&i )
    			h = e - i;
    		if(e&&h )
    			i = e - h;
    		
    // sixth triangle
    		if(i&&j )
    			f = i + j;
    		if(f&&j )
    			i = f - j;
    		if(f&&i )
    			j = f - i;
    		
    		printf("\n         %d  \n", a);
    		printf("\n      %d     %d  \n", b, c);
    		printf("\n   %d     %d     %d     \n", d, e, f);
    		printf("\n%d     %d     %d      %d \n", g, h, i, j);
    
    		getchar ();
    	}
    	
    	
    
    
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. GTK+ Programmng Help: Last Resort!
    By Reisswolf in forum Linux Programming
    Replies: 2
    Last Post: 04-23-2006, 10:23 PM
  2. Replies: 2
    Last Post: 02-20-2005, 08:26 AM
  3. Tsunami disaster.
    By anonytmouse in forum A Brief History of Cprogramming.com
    Replies: 23
    Last Post: 01-09-2005, 08:56 AM

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