PLEASE HELP C++ Newbie need help in fixing code

Discussion in 'Homework Help' started by Sundayy, Mar 8, 2011.

  1. Sundayy

    Thread Starter New Member

    Mar 7, 2011
    1
    0
    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:

    Code ( (Unknown Language)):
    1. #include<iostream>
    2. using namespace std;
    3.  
    4. int main()
    5. {
    6.     double weight,height,age;
    7.     double totalhatsize,totalJacketsize,totalwaist;
    8.  
    9.     double Hatsize=(weight/height)*(2.9);
    10.  
    11.     double adjustment = age>39?(age-10)/0.1: 0;
    12.     double Jacketsize = ((height*weight)/288)+ adjustment/0.125;
    13.  
    14.     double adjustment2 = age>29?(age-28)/2: 0;
    15.     double waist = ((weight/5.7) + adjustment2/0.1);
    16.  
    17. char choice;
    18.  
    19.     do
    20.     {
    21.         cout<<"Enter your Height\n";
    22.         cin>>height;
    23.  
    24.         cout<<"Enter your Weight\n";
    25.         cin>>weight;
    26.  
    27.         cout<<"Enter your Age\n";
    28.         cin>>age;
    29.  
    30.         totalhatsize =(weight,height);
    31.         totalJacketsize =(weight,height,age);
    32.         totalwaist =(weight,age);
    33.  
    34.         cout<<"totalhatsize"<<totalhatsize<<"\n";
    35.         cout<<"totalJacketsize"<<totalJacketsize<<"\n";
    36.         cout<<"totalwaist"<<totalwaist<<"\n";
    37.  
    38.         cout<<"To repeat calculation press'y'\n";
    39.         cin>>choice;
    40.     }
    41.  
    42.     while
    43.     (choice == 'y' || choice == 'y');
    44.  
    45.     return 0;
    46.  
    47. }
    48.  
    49.  
    50.  
    51.  
     
  2. mjhilger

    Member

    Feb 28, 2011
    119
    16
    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.
     
    Sundayy likes this.
Loading...