Thread: Hopefully a quickie

  1. #1
    Registered User
    Join Date
    Jan 2011
    Posts
    101

    Hopefully a quickie

    Code:
    #include <iostream>
    
    using namespace std;
    
    short heightfeet {};
    short heightinches {};
    short weightpounds {};
    float bmi{};
    
    int main()
    {
        cout<<"Please enter your height in feet : ";
        cin>>heightfeet;
    
        cout<<"Now the extra inches : ";
        cin>>heightinches;
    
        cout<<"And finally your weight in pounds : ";
        cin>>weightpounds;
    
        bmi=(weightpounds/2.2)/  ((heightfeet*12+heightinches)* 0.0254))*((heightfeet*12+heightinches)* 0.0254);
    
        cout<<endl<<endl<<"Your BMI is : "<<bmi;
    
        cout<<endl<<endl<<endl<<"I thank you......"<<endl;
    
        cin.get ();
        cin.get ();
    
        return 0;
    }
    The above code works as exected and gives the correct result (I have checked it with a BMI calculator on the web).

    My query is that my compiler gives an error warning as follows:
    line 21 expected ';' before ')' token.

    Can you please tell me why as it seems OK to me?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > The above code works as exected and gives the correct result (I have checked it with a BMI calculator on the web).

    > My query is that my compiler gives an error warning as follows:
    > line 21 expected ';' before ')' token.
    These two statements are contradictory.
    Until your code compiles WITHOUT errors, you haven't proved anything about your code.

    Start by counting your ( and ) on line 21
    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.

  3. #3
    Registered User
    Join Date
    Jan 2011
    Posts
    101
    Thanks Salem, I spent ages counting them and splitting them up and somehow got it to be right every time but have now found the error.

    Sorry to have wasted your time.

  4. #4
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    Get an IDE if you don't use one or get a better one.
    These kinds of problems should be picked up by the IDE even before compiling the code.

  5. #5
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    The root cause of the problem is trying to do too much on one line.
    Instead break the calculation up into parts that are stored in temporary variables. That way you wont need half as many brackets.
    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"

  6. #6
    Registered User
    Join Date
    Jan 2011
    Posts
    101
    Thanks for the helpful comments. I use Code::Blocks but that didn't show up any error with the brackets.
    iMalc, thanks for that comment, maybe I was trying to be too clever!!!

  7. #7
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    Have you adjusted the warning levels of your compiler yet. Right click the project in the Management Window then select Build Options, the start clicking the various warning check boxes. You should have at least Wall and Wextra checked. I recommend you check all warning options that are applicable to the language you are using.


    Jim

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Quickie on Arrays...
    By twomers in forum C++ Programming
    Replies: 4
    Last Post: 12-14-2005, 12:13 PM
  2. quickie...
    By Pyroteh in forum C++ Programming
    Replies: 8
    Last Post: 01-26-2005, 12:53 PM
  3. Quickie Q :o) (yea!!)
    By JohnMayer in forum C Programming
    Replies: 2
    Last Post: 07-23-2002, 12:09 PM
  4. Just a quickie
    By ActionMan in forum C++ Programming
    Replies: 4
    Last Post: 07-22-2002, 11:04 PM
  5. A quickie about fstream.h
    By Unregistered in forum C++ Programming
    Replies: 6
    Last Post: 10-02-2001, 07:10 PM