@Fresh Grass
Ok I got it with help from you, fresh grass, thanks. Here is what I got:
|
cout << weight/5.7 + (age>28?(age-28)/2:0*.1);
|
You came up with this formula I just rearranged a bracket
I came accross this small program as I was browsing on yahoo questions, I have been learning c++ for like a week so I decided to give it a try, here are the questions:
Write a program that asks for the user's height,weight and age and then computes clothing sizes according to the formulas.
~ 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 divied by 288 and then adjusting by adding 1/8 of an inch for each 10 years over age 30.( Note thath the adjustment only takes place after a full 10 years. So there is no adjustmen 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 added for age 30)
Use functions for each calculation.Your program should allow the user to repeat this calculation as often as the user wishes.
And here is my final code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
double hat (double w, double h);
double jacket (double w, double h, int a);
double waist (double w, double h, int a);
int main ()
{
double height;
double weight;
int age;
char yesno;
do{
system("CLS");
cout << "Please enter your height (in inches):" << endl;
cin >> height;
cout << "Please enter your weight (in pounds):" << endl;
cin >> weight;
cout << "Please enter your age (in years):" << endl;
cin >> age;
cout << "Your hat size is: " << hat(weight, height) << endl;
cout << "Your jacket size is: " << jacket(weight, height, age) << endl;
cout << "Your waist size is: " << waist(weight, height, age) << endl;
cout << "Do you want to run again?" << endl;
cin >> yesno;
}
while (yesno == 'y'|| yesno == 'Y');
system("PAUSE");
return 0;
}
double hat (double w, double h)
{
double r;
r = (w / h)*2.9;
return (r);
}
double jacket (double w, double h, int a)
{
double r;
r = (w*h) / 288;
if (a >= 30 && a < 40)
r = r + .125;
else if (a >= 40 && a < 50)
r = r + .25;
else if (a >= 50 && a < 60)
r = r + .375;
else if (a >= 60 && a < 70)
r = r + .5;
else if (a >= 70 && a < 80)
r = r + .625;
else if (a >= 80 && a < 90)
r = r + .75;
else if (a >= 90 && a < 100)
r = r + .875;
return (r);
}
double waist (double w, double h, int a)
{
double r;
r = w/5.7 + (a>28?(a-28)/2:0*.1);
return (r);
}
|
I understand there were probably much easier ways to do this but please keep in mind I just started coding about a week ago...