i need some help plz

Status
Not open for further replies.
it said that in the second line there that its not a called function i think its because of the 1 because its in red .
 
dude........conversion is right..... y are you using modulo? and i think it works as forced conversion from int to float, but i dont use it at all, just put in the multiplied values!
 
oi.....try taking out the equal to in the directives as well,
# define cent_feet 0.0333
#define cent_inch 0.4

it works fine that way
 
i_learn said:
oi.....try taking out the equal to in the directives as well,
# define cent_feet 0.0333
#define cent_inch 0.4

it works fine that way

I don't see how thats going to make any difference.
 
#include<stdio.h>
#define cent_feet 0.0333
#define cent_inch 0.4
#include<conio.h>
#include<math.h>


void main()
{
double cent,centf,centi;
clrscr();
printf("Enter your height in Cms\n");
scanf("%lf",&cent);
centf=cent*cent_feet;
centi=cent*cent_inch;
printf("%5.2lf cms\n%5.2lf inches\n%5.2lf feet",cent,centi,centf);
getch();
}


try it, it worked for me
 
Yeah that works but the output is incorrect. He was doing modulus because that is one way to look at the problem.

Centf will read the correct value because it is being cast as an integer.

Centi will not because you need to subtract the number of feet*cent_per_foot from the number of total centimeters, and then compute the inches.

In other words, assuming everything was an integer:

feet = centimeters * FEET_PER_CENTIMETER;

inches = (centimeters % CENTIMETERS_PER_FOOT) * INCHES_PER_CENTIMETER;

This, of course, does not work because modulus is an integer only arithmetic operation.

You could define your constants more appropriate like I did above like the following:

const double FEET_PER_CENTIMETER = 0.0333;
const double INCHES_PER_CENTIMETER = 0.4;
const double CENTIMETERS_PER_FOOT = 1. / FEET_PER_CENTIMETER;

then

Now, floor() is doing the same thing as truncate or explicit integer cast, but it is better 'style' to use floor or ceil than a cast:

centf = floor(cent * FEET_PER_CENTIMETER);
centi = floor((cent - floor(centf * CENTIMETERS_PER_FOOT)) * INCHES_PER_CENTIMETER);

As I say, though, you can just leave off 'floor()' and use '(int)', or just trust the compiler to do the cast implicitly.
 
arite i did it and it says that initializer element is not the same... by the way im using putty to connect to my school and we use vim .
 
I don't know what that means, I've never heard of it.

Don't you have to do some kind of "gcc -o blah blah.c"?
 
Status
Not open for further replies.
Back
Top Bottom