Intro to Computer Science project here. Calculates the hat, waist, and jacket size of the user when given age, height, and weight. Seems to output correctly.
Here are the guidelines for the assignment.
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 multiplied by 2.9
Jacket size (chest in inches) = height times weight divided by 288 and then adjusted by adding 1/8 of an inch for each 10 years over the age of 30. (Note that the adjustment only takes place after a full 10 years. Thus, 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. Thus, there is no adjustment for age 29, but 1/10 of an inch is added for age 30.)
Use functions for each calculation. (Thus, write 3 functions.)
I did this a tad hastily so pardon any messiness.
I am required to use namespace stdas it makes it easier for the teacher to read.
#include <iostream> using namespace std; double hat(double,double); double jacket(double,double,int); double waist(double,double,int); int main () { double height, weight; int age; char answer; cout.setf(ios::fixed); cout.setf(ios::showpoint); cout.precision(2); do { cout<< "Enter the user's height in inches: "; cin>>height; cout<< "Enter the user's' weight in pounds: "; cin>>weight; cout<< "Enter the user's' age: "; cin>>age; cout<< "\tThe user's Hat size: " << hat(weight ,height) << "\tThe user's Jacket size: "<< jacket( height, weight, age) << "\tThe user's Waist size: "<< waist( height, weight, age)<< "\n \nWould you like to continue (y/n)? "; cin>>answer; } while(toupper(answer) == 'Y'); return 0; } double hat(double weight ,double height) { return ((weight/height) * 2.9); } double jacket(double height,double weight,int age) { double size; int j; if (age>=30) { if((age % 10) !=0) age = age-(age%10); j= (age-30)/10; size =((height * weight) / 288)+((1.0/8)*j); } else size =((height * weight) / 288); return size; } double waist(double height,double weight,int age) { double size2; int k; if(age >= 28) { if((age % 2) !=0) age = age-(age%2); k = (age-28)/2; size2 = (weight/(5.7))+( (1.0/10)*k); } else size2 = weight / (5.7); return size2; }