Hey, I am having problems with the double waistsize function, I am not sure where I have gone wrong..I am not getting the outputs I should be.

waistsize should be user_weight divided by 5.7...adding 1/10 of an inch for each 2 years over age 28, so when it is 30 1/10 of an inch should be added, but nothing should be added when its 29.

#include "stdafx.h"
#include <iostream>
using namespace std;

double hatsize(double user_weight, double user_height); // hat size function declaration

double waistsize(double user_weight, int user_age); //waist size function declaration

int _tmain(int argc, _TCHAR* argv[])
{
	double user_height;
	double user_weight;
	int user_age;
	//char ans; // answer for do while loop. *repeat the program

	double hat; // hat size result
	double waist; // waist size result


	// User details entry
	cout << "Computing Clothing Sizes\n";
	cout << "________________________\n";
	cout << "Please enter your height in inches:\n";
	cin >> user_height;
	cout << "Please enter your weight in pounds:\n";
	cin >> user_weight;
	cout << "\n";
	cout << "Please enter your age:\n";
	cin >> user_age;
	cout << endl;

	hat = hatsize(user_weight, user_height); // hat size function call
	cout << "Your hat size is: ";
	cout << hat;
	cout << endl;

	

	waist = waistsize(user_weight, user_age); // waist size function call
	cout << "Your waist size is: ";
	cout << waist;
	cout << endl;

	return 0;
}

	//Hat size Formula
	
	double hatsize(double user_weight, double user_height)  // hatsize function heading
	{	
	return (user_weight / user_height * 2.9);
	}

	double waistsize (double user_weight, int user_age)  // waist size function heading
	{	
	int tempage; // is it even?
	double weightcalc;
		
	tempage = user_age;
	
    if (user_age >= 30) // nested if statements...
	{
		//do {
		if (user_age % 2 == 0) // if the age is even
		{
			tempage = tempage / 2.0;  // number of twos...
			tempage = tempage * 0.1;//...used for calculating number of times to add 1/10 of an inch
		}
		
		if (user_age % 2 != 0)
		{
			tempage = tempage - 1.0;   // if it wasnt an even number 1 will be taken away to make it even
			tempage = tempage / 2.0;  // number of twos...
			tempage = tempage * 0.1;//...used for calculating number of times to add 1/10 of an inch
		}

		//} while (user_age % 2 != 0); // while the remainder is greater then 0 it will loop.

	}

	//The weight calculation
	weightcalc = user_weight / 5.7;

	return (weightcalc + tempage);
	}
	






	//waistcalculation = user_weight / 5.7;




	// if age is not even then...
	// round down so that if number / number = 0


	//example 5%3 returns the value of 2, because 2 is the remainder after dividing 5 by 3

	//do
	//{
		//if (user_age >= 30)
		//{
			//waistcalculation = waistcalculation + 0.1; // add 1/10 to waist
			//count = count + 2;
		//}
	//}while (count < user_age);
//
	//return (waistcalculation);

	//}

> adding 1/10 of an inch for each 2 years over age 28
So you need to subtract that before doing the rest of the calculations which depend on that condition.

I still havent managed to get this right, the code looks logical to me...:confused:

...but it messes up with the number is 30 or above, and it adds stuff for every 1 number below 30!!

it should only be adding 0.1 every 2 above 28...30, 32, 34 etc

Please help!

#include "stdafx.h"
#include <iostream>
using namespace std;

double hatsize(double user_weight, double user_height); // hat size function declaration

double waistsize(double user_weight, int user_age); //waist size function declaration

int _tmain(int argc, _TCHAR* argv[])
{
	double user_height;
	double user_weight;
	int user_age;
	//char ans; // answer for do while loop. *repeat the program

	double hat; // hat size result
	double waist; // waist size result


	// User details entry
	cout << "Computing Clothing Sizes\n";
	cout << "________________________\n";
	cout << "Please enter your height in inches:\n";
	cin >> user_height;
	cout << "Please enter your weight in pounds:\n";
	cin >> user_weight;
	cout << "\n";
	cout << "Please enter your age:\n";
	cin >> user_age;
	cout << endl;

	hat = hatsize(user_weight, user_height); // hat size function call
	cout << "Your hat size is: ";
	cout << hat;
	cout << endl;

	

	waist = waistsize(user_weight, user_age); // waist size function call
	cout << "Your waist size is: ";
	cout << waist;
	cout << endl;

	return 0;
}

	//Hat size Formula
	
	double hatsize(double user_weight, double user_height)  // hatsize function heading
	{	
	return (user_weight / user_height * 2.9);
	}

	double waistsize (double user_weight, int user_age)  // waist size function heading
	{	
	int tempage; // temporary age - used to calculate additional inches
	int cont = 2;
	double weightcalc;
		
	tempage = user_age;
	tempage = tempage - 28;
	
    if (user_age >= 30) // nested if statements...
	{
		do {
		if (user_age % 2 == 0) // if the age is even
		{
		tempage = tempage / 2;  // number of twos...
		tempage = tempage * 0.1; //...used for calculating number of times to add 1/10 of an inch
		cont = 1;
		}
		else if (user_age % 2 != 0)	// if the age is odd
		{
		tempage = tempage - 1;   // if it wasnt an even number 1 will be taken away to make it even
		}
		} while (cont = 2); // while the remainder is greater then 0 it will loop.

	}

	//The weight calculation
	weightcalc = user_weight / 5.7;

	return (weightcalc + tempage);
	}

if user_age >= 30
temp_age = user_age - 30

Now you can use temp_age in any "for every 2 years after 30" calculation.

Sorry but I dont follow, if I have

if (user_age >= 30) // nested if statements...
	{
		temp_age = user_age - 30
		do {

etc and enter a number I just get nothing :S

You've declared tempage to be an int. So when you multiple 2 * .1 (for example, if the person is 30) you are getting 0.2. When this is stored as an int, it is stored as 0.

You need to store the result of x * 0.1 as a floating point type.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.