i need some help plz

Status
Not open for further replies.
You can replace floor by (int).

But I don't think int() is a "C-Style Cast". Eh, I'm having trouble remembering. You're probably safe if you stick with (int)(expression)
 
Yeah I guess for whatever reason it doesn't like the reference to floor, and I looked it up... floor takes a double.

It probably is not wanting to do an implicit cast there.

Just ignore that whole thing and use (int).
 
one prob!!
#include<stdio.h>
#include<math.h>
const double FEET_PER_CENTIMETER=0.033;
const double INCHES_PER_CENTIMETER=0.4;
const double CENTIMETERS_PER_FOOT=1.0/FEET_PER_CENTIMETER;
int main(void) {

int cent, centf, centi;

printf("COnvert Height Into Feet & Inches!\n");
printf("Please Enter Your Height In Centimeters: (<=0 to quit\n");
scanf("%d", &cent);
while (cent>0)
{
centf=(int)(cent*FEET_PER_CENTIMETER);
centi=(int)((cent-floor(centf*CENTIMETERS_PER_FOOT))*INCHES_PER_CENTIMETER);----what do i do in this line for the floor? change it to int too?

printf("%d cm= %d feet, %d inches\n", cent, centf, centi);
printf("Enter Another Height to COntinue: (<=0 to quit)\n");
scanf("%d", &cent);
}
printf("BYE!\n");
return 0;
}
/*----------------------------------------------------------------------*/
 
hey thanx man i got it to work but the calculations are all wrong i dunno why? here's the code=--

#include<stdio.h>
#include<math.h>
const double FEET_PER_CENTIMETER=0.033;
const double INCHES_PER_CENTIMETER=0.4;
const double CENTIMETERS_PER_FOOT=30.3;
int main(void) {

int cent, centf, centi;

printf("COnvert Height Into Feet & Inches!\n");
printf("Please Enter Your Height In Centimeters: (<=0 to quit\n");
scanf("%d", &cent);
while (cent>0)
{
centf=(int)(cent*FEET_PER_CENTIMETER);
centi=(int)(cent-(centf*CENTIMETERS_PER_FOOT))*INCHES_PER_CENTIMETER;
printf("%d cm= %d feet, %d inches\n", cent, centf, centi);
printf("Enter Another Height to COntinue: (<=0 to quit)\n");
scanf("%d", &cent);
}
printf("BYE!\n");
return 0;
 
somewhere i think i gotts use the % to get like the remainder of the feet and that little bit of feet that will remain has to be converted to inches
 
What are you getting for 'wrong calculations'?

I might expect it to be off by an inch or so depending on how you make it do the rounding, but not by more than that.

EDIT: You also need to have an explicit cast in the middle of your line

centi=(int)(cent - (int)(centf*CENTIMETERS_PER_FOOT))*INCHES_PER_CENTIMETER;
 
2 things, i dont understand the use of centf=(int)(cent*FEET_PER_CENTIMETER);
the (int) here?
and in a little more complicated manner, this is what i did,

#include<stdio.h>
#define cent_feet 0.0333
#define cent_inch 0.4
#include<conio.h>
#include<math.h>


void main()
{
double cent,c1,c2,centft,cms,centit;
int centf,centi,centii;
clrscr();
printf("Enter your height in Cms\n");
scanf("%lf",&cent);
centf=cent*cent_feet;
centft=cent*cent_feet;

c1=centft/cent_feet; //to get the remaining in inches
c2=centf/cent_feet;
centi=(c1-c2)*cent_inch;

centii=cent*cent_inch; //gettin the remainder for centimeters
centit=cent*cent_inch;
c1=centit/cent_inch;
c2=centii/cent_inch;
cms=(c1-c2);
printf("%d Feet\n%d inches\n%2.2lf cms",centf,centi,cms);
getch();
}

/*-----------------------------------
output
Enter your height in Cms
172
5 Feet
8 inches
2.00 cms

----------------------------*/
 
Status
Not open for further replies.
Back
Top Bottom