i need some help plz

Status
Not open for further replies.

kraze_101

Baseband Member
Messages
69
well i have this program to write that has to get a user input in centimeters and display it in feet and inches and the problem is that im getting an invvalid % operand ....This is the code.and ill put a [] to show where the problem is. its to get the lrft over feet to be changd into inches.


/* This program converts height in centimeters and
displays it into height in centimeters, feet, inches.*/


#include<stdio.h>
const double CENT_FEET=0.033;
const double CENT_INCHES=0.30;
int main(void) {

int cent, centf, centi, centl;

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*CENT_FEET;
[ centi=(int) cent % CENT_FEET*CENT_INCHES;]--->my problem
printf("%d cm= %.2d feet, .2%d inches\n", cent, centf, centi);
printf("Enter Another Height to COntinue: (<=0 to quit)\n");
scanf("%d", &cent);
}
printf("BYE!\n");
return 0;
}
/*----------------------------------------------------------------------*/


thanx if u can hellp
 
i tried it by changing the top part when declaring to like const int and the CENT_FEET and whatever and i tried it after i changed the first two but then i realised that the two numbers are still floating point numbers is there any way that i can declare them as floating point numbers and still change them to int and still make the program run without the *floating point exception*?
 
centf=(int) floor(cent*CENT_FEET);
centi=(int) (cent - floor(centf*CENT_FEET))*CENT_INCHES;

That would work better.
 
alright got one problem still sorry but it says that undefined reference to floor when i compile and it wont wok but the thing is i read up on it and im supposed to use math.h as a header file and if i do do i put it in as #include <math.h>?
 
TheHeadFL said:
centf=(int) floor(cent*CENT_FEET);
centi=(int) (cent - floor(centf*CENT_FEET))*CENT_INCHES;

That would work better.

I just realized I goofed. I was having a hard time following your constants and such and I guess I missed this.

It needs to read:

centf=(int) floor(cent*CENT_FEET);
centi=(int) (cent - floor(centf*(1/CENT_FEET))*CENT_INCHES;

The 1 over CENT_FEET is neccesary because what I actually meant was that it should be centf (the number of feet) times the number of centimeters in a foot, which should be 1/CENT_FEET.
 
Status
Not open for further replies.
Back
Top Bottom