PLEASE HELP C++ Newbie need help in fixing code

Thread Starter

Sundayy

Joined Mar 7, 2011
1
Hello:
I would like for the following code to calculate the following (see below code):
This program should calculate the hat, jacket and waist sizes based on the (any)values you enter.
I have completed the code but, its not calculating the correct output.
THANK YOU IN ADVANCE!



Given:

  • Hat size – the weight in pounds divided by the height in inches and then all that is multiplied by 2.9
  • Jacket size (chest in inches) – the height (in inches) times the weight is divided by 288 and then adjusted by adding 1/8 of an inch for each 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-39, but 1/8 is added for age 40…and another 1/8 is added, if he’s at least 50, etc.)
  • Waist in inches- the weight divided by 5.7 and then adjusted by adding 1/10 of an inch for each 2 years over age 28. (Note the adjustment 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, etc)
Use Each of these functions should be passed the appropriate values it needs (height, weight, age) and after it does the calculation, it should return the answer to the calling code which will and then print a message outputting what the answer was.


Note:


Please enter 'y' if you would like to try this again. Your program should allow the user to repeat this calculation as many times as he wants.

(Hint: First get your program to work once and then add a loop in main)


CODE:

Rich (BB code):
#include<iostream>
using namespace std;

int main()
{
    double weight,height,age;
    double totalhatsize,totalJacketsize,totalwaist;

    double Hatsize=(weight/height)*(2.9);

    double adjustment = age>39?(age-10)/0.1: 0;
    double Jacketsize = ((height*weight)/288)+ adjustment/0.125;

    double adjustment2 = age>29?(age-28)/2: 0;
    double waist = ((weight/5.7) + adjustment2/0.1);

char choice;

    do
    {
        cout<<"Enter your Height\n";
        cin>>height;

        cout<<"Enter your Weight\n";
        cin>>weight;

        cout<<"Enter your Age\n";
        cin>>age;

        totalhatsize =(weight,height);
        totalJacketsize =(weight,height,age);
        totalwaist =(weight,age);

        cout<<"totalhatsize"<<totalhatsize<<"\n";
        cout<<"totalJacketsize"<<totalJacketsize<<"\n";
        cout<<"totalwaist"<<totalwaist<<"\n";

        cout<<"To repeat calculation press'y'\n";
        cin>>choice;
    }

    while
    (choice == 'y' || choice == 'y');

    return 0;

}
 

mjhilger

Joined Feb 28, 2011
118
Following main() your declarations are static at the time of execution as the variables are not defined as functions.
should be:
double Hatsize(double fweight, double fheight){

ret ((fweight/fheight)*(2.9));}

I have added the "f" on the front of your variables because the scope is only in the function.
Then inside your do loop you call the function in this way

TotalHatsize = Hatsize(weight,height);

You will have to modify all your functions defs following main in a similar way and then change the way they are called inside the do loop.
 
Top