Results 1 to 9 of 9
Like Tree2Thanks
  • 1 Post By jakncoke
  • 1 Post By jakncoke

Math Help - C++ programming. i need help in this.plz help me!

  1. #1
    Junior Member
    Joined
    Feb 2013
    From
    Canada
    Posts
    31

    C++ programming. i need help in this.plz help me!

    Between 18.5 and 25.0 (inclusive)

    i need to put that statement in if loop but its not working
    my if loop is like this

    if (B<25.0 | B>18.5)

    how can i get it right ?
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Senior Member jakncoke's Avatar
    Joined
    May 2010
    Posts
    388
    Thanks
    80

    Re: C++ programming. i need help in this.plz help me!

    the | should be replaced with ||
    | is a bitwise or

    Also since the statement said inclusive you should have

    if(B<=25.0 || B>=18.5)
    Thanks from Riana
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Junior Member
    Joined
    Feb 2013
    From
    Canada
    Posts
    31

    Re: C++ programming. i need help in this.plz help me!

    #include <iostream>

    using namespace std;

    int main()
    {
    double h,w;
    double B=1;
    cout<<"Please enter your weight in kg :"<<endl;
    cin>>w;
    cout<<"Please enter your height in meters :"<<endl;
    cin>>h;
    B*=w/(h*h);
    cout<<"The BMI is :"<<B<<endl;

    if (B<=25.0 || B>=18.5)

    cout<<"This is normal weight"<<endl;

    else if (B>25.1)

    cout<<"This is overweight"<<endl;

    else if (B<18.0)
    cout<<"This is underweight"<<endl;

    return 0;
    }



    this is my code...if the weight is less than or more than the normal it give both the statements and i only need the true one.
    Follow Math Help Forum on Facebook and Google+

  4. #4
    Senior Member jakncoke's Avatar
    Joined
    May 2010
    Posts
    388
    Thanks
    80

    Re: C++ programming. i need help in this.plz help me!

    use the brackets after your if { } else if { } else if { }

    other wise you are doing something called chaining if statements which is not what you want
    Follow Math Help Forum on Facebook and Google+

  5. #5
    Junior Member
    Joined
    Feb 2013
    From
    Canada
    Posts
    31

    Re: C++ programming. i need help in this.plz help me!

    its still the same problem if the weight is over it gives normal no matter what.....my first if statement is wrong i know that but i cant figure it out how to get those values and the values between in it, just for the normal weight like 18-25.
    Follow Math Help Forum on Facebook and Google+

  6. #6
    Senior Member jakncoke's Avatar
    Joined
    May 2010
    Posts
    388
    Thanks
    80

    Re: C++ programming. i need help in this.plz help me!

    give me the h,w values you are using to test it out.
    Follow Math Help Forum on Facebook and Google+

  7. #7
    Junior Member
    Joined
    Feb 2013
    From
    Canada
    Posts
    31

    Re: C++ programming. i need help in this.plz help me!

    3. Body Mass Index
    The Body Mass Index (BMI) is one of the calculations used by doctors to assess an adult’s health.
    The doctor measures the patient’s height (in metres) and weight (in kilograms), then calculates the BMI using the formula

    Write a program which prompts for the patient’s height and weight, calculates the BMI, and displays the corresponding message from the table below.

    BMI Category Message
    More than 25 Overweight
    Between 18.5 and 25.0 (inclusive) Normal weight
    Less than 18.5 Underweight

    Sample Input 1 (user input is in italics)
    Enter weight: 69
    Enter height: 1.73
    Output for Sample Input 1
    Normal weight
    Explanation for Output in Sample Input 1
    The BMI is 69=(1:73 _ 1:73), which is approximately 23.0545. According to the table, this is a “Normal weight”.
    Sample Input 2 (user input is in italics)
    Enter weight: 84.5
    Enter height: 1.8
    Output for Sample Input 2
    Overweight
    Explanation for Output in Sample Input 2
    The BMI is 84.5/(1.8 times 1:8), which is approximately 26.0802. According to the table, this is “Overweight”.





    this is the whole question.
    Follow Math Help Forum on Facebook and Google+

  8. #8
    Senior Member jakncoke's Avatar
    Joined
    May 2010
    Posts
    388
    Thanks
    80

    Re: C++ programming. i need help in this.plz help me!

    oh, sorry, you should use an and statement not an or, use &&, instead of ||
    Thanks from Riana
    Follow Math Help Forum on Facebook and Google+

  9. #9
    Junior Member
    Joined
    Feb 2013
    From
    Canada
    Posts
    31

    Re: C++ programming. i need help in this.plz help me!

    thank you so much ....it works now!
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Replies: 3
    Last Post: February 20th 2013, 06:16 PM
  2. Linear Programming Help
    Posted in the Business Math Forum
    Replies: 1
    Last Post: February 20th 2010, 12:28 AM
  3. Programming For HP 48G+
    Posted in the Calculators Forum
    Replies: 0
    Last Post: February 3rd 2009, 03:09 AM
  4. Replies: 1
    Last Post: November 17th 2008, 03:18 AM
  5. Please help on R programming
    Posted in the Math Software Forum
    Replies: 0
    Last Post: August 16th 2008, 02:51 AM

Search Tags


/mathhelpforum @mathhelpforum