Hey I have this prog that i'm working on, starting my first c++ class and kind of a n00b to programming
here it is
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{ int remainder,remainder2,yards,feet,inches;
float centi,inche5;
cout<<"What is the length in Centimeters"<<endl;
cin>>centi;
//convert to nearest inch
inche5=centi/2.54;
inches=static_cast<int>(inche5);
//Compute Yards
yards=inches/36;
//Drop Remainder To Feet
remainder=inches%36;
//Compute Feet
feet=remainder/12;
//Drop Remainder To Inches
remainder2=remainder%12;
cout<<"Yards="<<yards<<endl;
cout<<"Feet="<<feet<<endl;
cout<<"Inches="<<remainder2<<endl;
system("pause");
return 0;
}
i used static_cast to convert float to int without runtime errors, the problem is that static_cast rounded down so the output tended to be 1 less inch then what's mathmatically correct...is there a better way to convert float to int or somehow name all variables as int but still keep the conversion of cm/2.54?
thanks for all your help
