Hey guys, I'm working on my first C ++ program for school. For some reason, I get the following error when trying to compile it:
`truncate' undeclared (first use this function)
Full source code:
#include <iostream>
#include <math.h>
using namespace std;
#define CENTIMETERS_IN_INCH 2.54
#define POUNDS_IN_KILOGRAM 2.2
int main() {
double feet, inches, centimeters, weight_in_kg, weight_in_lbs;
cout << "Enter height (feet): ";
cin >> feet;
cout << "Enter (inches): ";
cin >> inches;
centimeters = ((12 * feet) + inches) * CENTIMETERS_IN_INCH;
centimeters = truncate(centimeters);
printf("Someone that is %g' %g\" would be %g cm tall", feet, inches, centimeters);
weight_in_kg = truncate(18.5 * centimeters);
weight_in_lbs = round(weight_in_kg * POUNDS_IN_KILOGRAM);
printf("18.5 BMI would correspond to about %g kg or %g lbs", weight_in_kg, weight_in_lbs);
weight_in_kg = truncate(25 * centimeters);
weight_in_lbs = round(weight_in_kg * POUNDS_IN_KILOGRAM);
printf("25.0 BMI would correspond to about %g kg or %g lbs", weight_in_kg, weight_in_lbs);
cin >> feet;
return 0;
}
double round(double d) {
return floor(d + 0.5);
}
double truncate(double d) {
return round(double * 10) / 10;
}
Any help would be greatly appreciated. Thanks.
Pooch source
share