Like Tree2Likes
  • 2 Post By iMalc

Hopefully a quickie

This is a discussion on Hopefully a quickie within the C++ Programming forums, part of the General Programming Boards category; Code: #include <iostream> using namespace std; short heightfeet {}; short heightinches {}; short weightpounds {}; float bmi{}; int main() { ...

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

    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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,546
    > 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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Jan 2011
    Posts
    99
    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
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,498
    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.
    Manasij Mukherjee | gcc-4.8.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



  5. #5
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,304
    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.
    Elysia and rags_to_riches like this.
    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
    99
    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
    2,753
    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, 11:13 AM
  2. quickie...
    By Pyroteh in forum C++ Programming
    Replies: 8
    Last Post: 01-26-2005, 11:53 AM
  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

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