Thread: problem with ; at end of if statement

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

    problem with ; at end of if statement

    if (q==s);
    cout<<fixed<<setprecision(5)<<a*z<<endl;
    else cout<<fixed<<setprecision(5)<<a*x<<endl;


    error: else without a previous if

    Thanks in advance

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    Code:
    if (q==s);
    That semi-colon shouldn't be there.
    If you understand what you're doing, you're not learning anything.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    I fixed your thread title
    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. #4
    Programming King Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Middle of NoWhere
    Posts
    320
    Compiler must generate an error in this case as else is being used without any if.
    What compiler reading is;
    It reads your if statement and as you didn't put any opening, closing bracket, so it reads ; as a statement and ignores remaining... It then takes cout object as a separate line and when it looks at else, it generates an error as there is no preceding if....
    I don't care if someone doesn't like me, i was not put on earth to entertain everyone.

    No King, no Queen, I am the ACE of battle.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem building Quake source
    By Silvercord in forum Game Programming
    Replies: 16
    Last Post: 07-11-2010, 09:13 AM
  2. Stack problem - I've hit a wall!
    By miniwhip in forum C Programming
    Replies: 7
    Last Post: 11-14-2007, 03:05 AM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. Replies: 3
    Last Post: 04-27-2005, 11:50 AM
  5. Replies: 2
    Last Post: 05-10-2002, 04:16 PM