|
-
December 29th, 2011, 05:34 PM
#1
Simple Program, wrong answers
I am making a simple C++ program to determine hat, jacket, and waist size. I cannot get the correct answer for the last two sizes. Here is my code:
Code:
#include<iostream.h>
#include<math.h>
double hatsize(double h, double w, double a, double hs);
double jacketsize(double h, double a, double w, double jadd, double js);
double waistsize(double w, double a, double wadd, double ws);
int main ( )
{
double h, w, a, hs, js, ws, jadd, wadd;
char y = 'y';
while(y=='y')
{
jadd = 0;
wadd = 0;
hs = hatsize(h, w, a, hs);
js = jacketsize(h, a, w, jadd, js);
ws = waistsize(w, a, wadd, ws);
cout<< endl << "Your hat size is " << ceil(hs) << "." << endl << "Your jacket size is " << ceil(js) << " inches." << endl << "Your waist size is " << ceil(ws) << " inches." << endl << endl << "Would you like to try again? (y or n): ";
cin >> y;
system("CLS");
}
return 0;
}
double hatsize(double h, double w, double a, double hs)
{
cout<< "Enter your height in inches: ";
cin>> h;
cout<< "Enter your weight in pounds: ";
cin>> w;
cout<< "Enter your age: ";
cin>> a;
hs=(w/h)*2.9;
return hs;
}
double jacketsize(double h, double a, double w, double jadd, double js)
{
if(a>30)
{
jadd = floor((a-30)/10)/8;
}
js = ((h*w)/288)+jadd;
return js;
}
double waistsize(double w, double a, double wadd, double ws)
{
if(a>28)
{
wadd = floor((a-28)/2)/10;
}
ws = (w/5.7)+wadd;
return ws;
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|