6 Replies - 7431 Views - Last Post: 19 April 2010 - 06:28 PM Rate Topic: -----

#1 coolhandfluke  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 4
  • Joined: 19-April 10

Calculating height based on femur length

Posted 19 April 2010 - 05:14 PM

Hello,

I'm working on some problems for my c++ class and this one is giving me a lot of trouble. According to the question (which is about calculating a person's height based on their gender and femur length) I'm supposed to write a program that has the following input:

Gender of that adult: (char type)
A height determined by foot bone: (float type)
Length of thighbone of an adult: (float type)

And has an output of both the input height and the calculated height (float type). Then i am to determine if the height based on the thighbone is consistent with the height determined by the foot bone (differs by no more than 0.5 inches in absolute value), and indicate the answer as "consistent" or "not consistent".

So far this is what I have:

#include <iostream>
#include <math.h>
#include <fstream>

using namespace std;

int main ()
{
char gender; //THE PERSON'S GENDER
float w; //THE HEIGHT OF A MAN BASED ON THE LENGTH OF THEIR BONES
float x; //THE HEIGHT OF A WOMAN BASED ON THE LENGTH OF THEIR BONES
float y; //THE LENGTH OF THE PERSON'S THIGHBONE
float z; //THE DIFFERENCE BETWEEN THE TWO HEIGHT ESTIMATES

//THIS FUNCTION DISPLAYS THE INFORMATION ABOUT WHAT THIS PROGRAM DOES
//AND TAKES INPUT FROM THE USER IN A SPECIFIC FORM.

cout << "This program will determine the height of a person based on their gender and the length of their thighbone." <<endl;
cout << "It will also determine if this height is consistent with the height estimated by the bones in their feet." <<endl;
cout << "" <<endl;
cout << "What is the person's gender?  Please type M, m, F, or f: " <<endl;
cin >> gender;
cout << "What is the person's estimated height based on the bones in their feet (in inches)?: " <<endl;
cin >> w;
cout << "What is the length of the person's thightbone (in inches)?: " <<endl;
cin >> y;

}

bool z (float z) //Determines whether the two measurements are close to each other.
{
if (z <=.5 && >=(-.5)) {
cout << "The two estimates are consistent with each other." <<endl;
else 
cout << "The two estimates are not consistent with each other." <<endl;
} 

bool gender (char gender) //Return an error message if the gender is input improperly.
{
if (gender != 'f' || 'F' || 'm' || 'M' )
return << "Error.  Please restart program." << endl;
else
cin >> gender;
}



I'm at a loss for what to do next and I'm not sure if any of that code is actually any good. Thanks very much for any suggestions anyone might have.

Is This A Good Question/Topic? 1
  • +

Replies To: Calculating height based on femur length

#2 coolhandfluke  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 4
  • Joined: 19-April 10

Re: Calculating height based on femur length

Posted 19 April 2010 - 05:33 PM

anyone?
Was This Post Helpful? 0
  • +
  • -

#3 Oler1s  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1397
  • View blog
  • Posts: 3,884
  • Joined: 04-June 09

Re: Calculating height based on femur length

Posted 19 April 2010 - 05:36 PM

Quote

I'm at a loss for what to do next
You tell us. If you could wave a magic wand, what would you wish for next?

Quote

and I'm not sure if any of that code is actually any good
So gather evidence. Compile and build code. Then run and test with various inputs. Check if the results are consistent with what you calculate by hand. If they are, it's evidence code is "good". If not consistent, you have evidence code is bad.
Was This Post Helpful? 0
  • +
  • -

#4 coolhandfluke  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 4
  • Joined: 19-April 10

Re: Calculating height based on femur length

Posted 19 April 2010 - 05:48 PM

You tell us. If you could wave a magic wand, what would you wish for next?

Sleep. I've worked 120 hours the past two weeks and I'm taking 17 credit hours this semester. I'm feeling a little burnt out right now...like my brain isn't functioning the way it should.

As far as the code is concerned, I think I need to put the equation in that determines the person's height but I'm not sure where.


So gather evidence. Compile and build code. Then run and test with various inputs. Check if the results are consistent with what you calculate by hand. If they are, it's evidence code is "good". If not consistent, you have evidence code is bad.


If I could get that far I would have already, but I can't and that's why I'm asking for help.
Was This Post Helpful? 0
  • +
  • -

#5 Oler1s  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1397
  • View blog
  • Posts: 3,884
  • Joined: 04-June 09

Re: Calculating height based on femur length

Posted 19 April 2010 - 05:51 PM

Quote

If I could get that far I would have already, but I can't and that's why I'm asking for help.
What do you mean you can't get that far? Why not? What's stopping you?

Quote

As far as the code is concerned, I think I need to put the equation in that determines the person's height but I'm not sure where.
That's still not a question :)

This post has been edited by Oler1s: 19 April 2010 - 05:52 PM

Was This Post Helpful? 0
  • +
  • -

#6 coolhandfluke  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 4
  • Joined: 19-April 10

Re: Calculating height based on femur length

Posted 19 April 2010 - 05:56 PM

Does what I have so far look ok? Where should I put the equation in the code? should the gender if/else statement go first? followed by the equation to determine height? and then the if/else statement that determines whether the two estimates are close enough?
Was This Post Helpful? 0
  • +
  • -

#7 Oler1s  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1397
  • View blog
  • Posts: 3,884
  • Joined: 04-June 09

Re: Calculating height based on femur length

Posted 19 April 2010 - 06:28 PM

You said:

Does what I have so far look ok?

Me, before said:

So gather evidence. Compile and build code. Then run and test with various inputs. Check if the results are consistent with what you calculate by hand. If they are, it's evidence code is "good". If not consistent, you have evidence code is bad.
If at any stage, you cannot proceed (compile errors, link errors, runtime errors, incorrect output, etc.), you have evidence of bad code.

Quote

Where should I put the equation in the code?
In the correct location. Rather than asking where to put equations, write down on paper the exact steps you would follow.

Forget about programming. Pretend you are the one who has to determine if the height is consistent or not. You are given the three pieces of information. Tell me step by step what you would do with pen and paper (and calculator).
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1