Go Back   PCMech Forums > Help & Discussion > Web Design / Development

Need Some Help? Type Your Keywords Here:

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Old 04-17-2001, 08:11 AM   #1
Member (4 bit)
 
Join Date: Apr 2001
Posts: 9
I need some advice on these formulas for a program I'm writing. I need three. Here is the program:
The program is suppose to read a persons height (in feet and inches - 2 variables), weight, and age, and then computes clothing sizes according to the formulas:

Follow program I wrote for formulas

>#include
> #include
> using namespace std;
>
> int main()
> {
> int age, weight, feet, inches;
> double hat_size, jacket_size, waist_size;
>
> cout << "Enter the feet in your height: ";
> cin >> feet;
> cout << "Enter the inches in your height: ";
> cin >> inches;
> cout << "Enter your weight: ";
> cin >> weight;
> cout << "Enter your age: ";
> cin >> age;
>
//------------Original Formala contraints-----------------
> //hat_size = weight in pounds divided by height in inches and all that multiplied by 2.9
> //jacket_size (chest in inches) = height times weight
> //waist_size = weight divided by 5.7.
>//----------------------------------------------------

> hat_size = hat_size = weight / (feet * 12 + inch) * 2.9;
> jacket_size = feet, inches * weight / 288; (this formula I know is wrong Please help correct it. Look at constraints for jacket size formula above)
> waist_size = weight / 5.7;

> cout << fixed << setprecision ( 2 ) << endl;
> cout << "The following are your clothing sizes: \n"
< cout << "Hat size: " < > cout << "Jacket size: " << jacket_size << endl;
> cout << "Waist size: " << waist_size << endl;
>
> return 0;
----------------------------------------------------------
Problem: The 3 formulas in the original program above should be modified to the following:

-Hat size: hat_size = weight / (feet * 12 + inch) * 2.9;
remains unchanged.

-However jacket size and waist formulas will change to the
following

Jacket size (chest in inches) = height times weight divided by 288 and then adjusted by adding 1/8 of an inch for each of 10 years over age 30. (Note that the adjustment only takes place after a full 10 years. So there is no adjustment for ages 30 through 39, but 1/8 of an inch is added for age 40.)

Waist in inches = weight divided by 5.7 and then adjusted by adding 1/10 of an inch for each 2 years over age 28. (Note that the adjustment only takes place after a full 2 years. So, there is no adjustment for age 29, but 1/10 of an inch is added for age 30.)

Well this program is not that hard. I just need to make sure the original 3 formulas are correct in the program.
The modifications above I sure could use some advice on how to do them.
Thanks a lot for your input

sting568 is offline   Reply With Quote
Old 04-17-2001, 10:59 PM   #2
Member (12 bit)
 
Paul Victorey's Avatar
 
Join Date: Mar 1999
Location: MN or WI
Posts: 3,017
Well, if your second formula should be height in inches * weight, it's:

(feet * 12 + inches)*weight;


However, you MUST change your first formula.

You have:

weight / (feet * 12 + inch) * 2.9;

The problem with this is:

It first evaluates (feet * 12 + inch), which are all int values, so the denominator of the initial division will be an int. weight is also an int. So, the division becomes INTEGER division -- so it only takes the nearest whole number.

By doing this:

2.9 * weight / (feet * 12 + inch);

weight is first multiplied by 2.9. Since 2.9 is of type float, weight is "promoted" to type float, and a float divided by an integer will use floating point division (it will make the int into a float).

You could also do this:

(float) weight / (feet * 12 + inch) * 2.9; // explicitly cast weight to a float

or this:

weight / (feet * 12.0 + inch) * 2.9 // 12.0 is a float, which makes the denominator a float, which makes the division floating point

which should both return the same as the first suggestion I had, but will be DIFFERENT from the result that you would get from the first part.

The third one is OK because the int again will be promoted to float, because the compiler will convert int/float to float/float.

To get how many "full tens of years" happen since age 30, use integer division.

(x - 30)/10 will return ZERO for x 30-39, ONE for x 40-49, etc.

So, to generate the correction factor for ever 10 years over 30, use this:

int correctionFactor = (age - 30)/10
if (correctionFactor < 0) // if age < 20, (I'll leave it to you to figure out why it's < 20 not < 30)
correctionFactor = 0; //we want no correction

I have a feeling this chapter focuses on integer vs. floating point arithmetic? =]


[Edited by Paul Victorey on 04-18-2001 at 12:03 AM]
__________________
Paul M. Victorey
------------------
I am not responsible for any problems that may arise as a result of following my advice. This includes, but is not limited to, computer failure, loss of data, nuclear war, famine, boils, no clean laundry, your daughter running off with a biker gang, or armageddon. Take my advice at your own risk.
Paul Victorey is offline   Reply With Quote
Old 04-18-2001, 03:00 PM   #3
Member (4 bit)
 
Join Date: Apr 2001
Posts: 9
Hey thanks for your advice on the formulas. Your analaysis makes sence and the chapter was on Data types and operators. I have a good understanding about c++ program flow but formulas are sometimes hard to come up with. I really did not know how to program this program to compute something every ten years. When I saw your formula it made total sense. Sometimes you look at something way to hard and the answer is simple. But thanks I know it probably took like nothing to do it but I was on the machine most of the day trying to figure out the formulas. I just need to brush up on my math skills. But thanks!
Fred
sting568 is offline   Reply With Quote
Reply

Bookmarks

Still Need Help? Type Your Keywords Here:


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 07:11 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
SEO by vBSEO 3.6.0 PL2