Le Sat, 21 Feb 2009 06:07:43 -0800 (PST),
happytoday a écrit :
> Here it is a primitive conversion program from meter to
> yards,inches,feets. Should I get the result of 1 inches when I enter
> 0.0245 meter.
Ouch !
> #include "stdio.h"
> #include "stdlib.h"
Better to write:
#include <stdio.h>
#include <stdlib.h>
> void input(float *);
> void convert(float *,int *,int *,int *);
> char another(void);
Where's defined another?
> float main ()
Oops !
int main (void)
look better.
> {
> int yards,feet,inches;
> float meter;
Why float meter and int the others?
That is, it's your choice...
> do {
> //system("clear");
> input(&meter);
> convert(&meter,&yards,&feet,&inches);
> printf("\n %.4f meter is = %d yards %d feet %d inches
> ",meter,yards,feet,inches);
> } while (another()=='y');
Same as previous, what's 'another'
Some indentation and spacing will help reading code.
> return 0;
Hmmm, remember 'float main ()'
> }
>
>
> void input(float *m)
> {
> printf("\nEnter size in meter :");
A flush here in case of...
> scanf("%f",m);
It is advisable to check scanf...
> printf("\nYou have entered size in meter %.4f\n",*m);
>
> }
>
>
> void convert(float *m,int *y,int *f,int *i)
I think it's better to separate calculations here.
One by function, by example, and in case you want
int for inch and float for meter:
int meter2inch(float *);
float inch2meter(int *);
and so on...
> {
> float remainder=0.0;
> (remainder)=((*m) * 100.0) / 2.54;
> *y=(remainder)/36.0;
> (remainder)=(remainder)-(*y)*36.0;
> *f=(remainder)/12.0;
> *i=(remainder)-(*f)*12.0;
Strange method of conversion ?
inch = meter / 0,0254 (simply)
and ditto for the rest.
> printf("\n %.4f meter is = %d yards %d feet %d inches ",*m,*y,*f,*i);
> }
>
Well, tries to resolve these issues, the rest we will see later
if necessary...
That's all for now.
--
Jacques.