Thread: Weird if/else error

  1. #1
    Registered User
    Join Date
    Aug 2007
    Posts
    270

    Question Weird if/else error

    when i do this:
    Code:
    for(s=0; s<full; s++)
    						{
    							if((int)abs((ident[s].top/ident[s].bottom) - (tempIDTop/tempIDBottom)) < value);
    							{
    								value = (int)abs((ident[s].top/ident[s].bottom) - (tempIDTop/tempIDBottom));
    								positionID = s;
    							}
    							
    															
    						}
    It works.
    But if i add an else like this it doesnt work:
    Code:
    for(s=0; s<full; s++)
    						{
    							if((int)abs((ident[s].top/ident[s].bottom) - (tempIDTop/tempIDBottom)) < value);
    							{
    								value = (int)abs((ident[s].top/ident[s].bottom) - (tempIDTop/tempIDBottom));
    								positionID = s;
    							}
    							else
    							{
    								printf("%d\n", (int)abs((ident[s].top/ident[s].bottom) - (tempIDTop/tempIDBottom)));
    							}								
    						}
    I get this error:
    Code:
    process.c:266: error: ‘else’ without a previous ‘if’
    Line 266 is the line starting with else.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Code:
    if((int)abs((ident[s].top/ident[s].bottom) - (tempIDTop/tempIDBottom)) < value);

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Aug 2007
    Posts
    270
    ah of course, dont know why it didnt complain before
    Thanks

  4. #4
    The larch
    Join Date
    May 2006
    Posts
    3,573
    Because it is legal to have an if block that does nothing.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. what am I missing? (Program won't compile)
    By steals10304 in forum C Programming
    Replies: 3
    Last Post: 08-25-2009, 03:01 PM
  2. Linking to shlwapi.lib in C, MSVC CMD.
    By Joerge in forum Windows Programming
    Replies: 4
    Last Post: 08-07-2009, 05:18 PM
  3. how do you resolve this error?
    By -EquinoX- in forum C Programming
    Replies: 32
    Last Post: 11-05-2008, 04:35 PM
  4. Quantum Random Bit Generator
    By shawnt in forum C++ Programming
    Replies: 62
    Last Post: 06-18-2008, 10:17 AM
  5. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 10:33 AM