Thread: Simple fix.

  1. #1
    Registered User
    Join Date
    Mar 2008
    Posts
    1

    Simple fix.

    Hi, I want to perform the following algorithm but dont know where to place brackets and semicolons. Can someone show mw plz.

    Code:
    if ( i > 20 )
    if ( i == 10 )
    printf( “Here I am...” );

  2. #2
    Registered User
    Join Date
    Mar 2008
    Posts
    43
    Quote Originally Posted by greg_yia View Post
    Hi, I want to perform the following algorithm but dont know where to place brackets and semicolons. Can someone show mw plz.

    Code:
    if ( i > 20 )
    if ( i == 10 )
    printf( “Here I am...” );

    The example did not really make sense but heres a few guesses...

    Code:
    #include <stdio.h>
    
    int main()
    {
    	int i;
    	
    	for(i = 0; i < 30; i++)
    	{
    		if(i > 20)
    		{
    			printf("i > 20 and equals %d\n", i);
    		}
    		if(i == 10)
    			printf("i == 10\n");
    	}
    
    	return 0;
    }
    
    }
    you don't always need the braces.

  3. #3
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    maybe you want
    Code:
    if(i>20 || i == 10)
       puts("Here I am");
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ code need help to fix
    By McReal in forum C++ Programming
    Replies: 9
    Last Post: 05-12-2007, 02:48 PM
  2. Very simple question, problem in my Code.
    By Vber in forum C Programming
    Replies: 7
    Last Post: 11-16-2002, 03:57 PM
  3. ...deceptively simple...
    By Sebastiani in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 07-29-2002, 12:51 PM
  4. Need help with simple DAQ program
    By canada-paul in forum C++ Programming
    Replies: 12
    Last Post: 03-15-2002, 08:52 AM
  5. The following code has one simple error.....
    By bluehead in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 11-08-2001, 07:45 PM