(E-Mail Removed) wrote:

> That program does not yield and respond correctly espcially for the

> pointers (*f),(*i)

> in

> print_divide_meter_into(&meter,&yds,&ft,&ins);
Please post code that compiles.

Yours did not.

If I fix that and all warnings:

#include "stdio.h"

/*Module 2 : using pointers in a function to convert Size Entry

in meter to sizes of Yards,feet,inches-----*/

void input_meter(float *m);

void divide_meter_into(float *m,float *y,float *f,float *i);

void print_divide_meter_into(float *m, float *y, float *f, float *i);

char another (void);

int main (void)

{

float meter;

float yds,ft,ins;

char another();

/* system("cls");

*/

do {

input_meter(&meter);

divide_meter_into(&meter,&yds,&ft,&ins);

print_divide_meter_into(&meter,&yds,&ft,&ins);

} while (another() == 'y');

return 0;

}

void input_meter(float *m)

{

printf("\nEnter size in meter :");

scanf("%f",&(*m));

printf("\nYou have Entered % f",*m);

}

void divide_meter_into(float *m,float *y,float *f,float *i)

{

float temp_m=0;

temp_m=(*m)*100.0/2.54;

(*y)=(temp_m)/36.0;

(temp_m)=(temp_m)-(*y)*36.0;

(*f)=(temp_m)/12.0;

(*i)=(temp_m)-(*f)*12.0;

}

void print_divide_meter_into(float *m, float *y, float *f, float *i)

{

printf("\n Meter %f is = %f yards %f feet"

" %f inches",(*m),(*y),(*f),(*i));

}

char another (void)

{

char answer;

printf("\n do ou want to procees (y/n)");

scanf("\n");

scanf("%c",&answer);

return (answer);

}

Back to the original problem:

<snip!>

> divide_meter_into(float *m,float *y,float *f,float *i)

> {

> float temp_m=0;

> temp_m=(*m)*100.0/2.54;

> (*y)=(temp_m)/36.0;

> (temp_m)=(temp_m)-(*y)*36.0;
Here, you try to calculate

temp_m = temp_m - (temp_m/36.0)*36.0;

Guess what.

> (*f)=(temp_m)/12.0;

> (*i)=(temp_m)-(*f)*12.0;

> printf("\n Meter %f is = %f yards %f feet %f

> inches",(*m),(*y),(*f),(*i));

> }
<snip!>

What are you trying to do?

If you want integer division, use integers, "/" and "%".

The version I think you want:

#include "stdio.h"

#include "ctype.h"

#include "limits.h"

#define METER_PER_INCH 0.0254

typedef struct {

double meter;

struct {

double inch;

long int yard;

unsigned char foot;

} imperial;

} metric_imp;

int input_meter (double *meters);

void cleanup_stdin (void);

void calculate_yfi (metric_imp *in);

void print_metric_imp (metric_imp *in);

int do_another (void);

int main (void)

{

metric_imp input = {0};

do {

if (input_meter(&input.meter)) {

calculate_yfi(&input);

print_metric_imp(&input);

}

cleanup_stdin();

} while (do_another());

return 0;

}

int input_meter(double *m)

{

printf("\nEnter size in meter: ");

fflush(stdout);

if (1 == scanf("%lf", m)) {

return 1;

}

else {

fprintf(stderr, "Input error\n");

return 0;

}

}

void cleanup_stdin (void)

{

int c;

while (EOF != (c=getchar()))

if (c=='\n')

break;

}

void calculate_yfi (metric_imp *in)

{

in->imperial.inch = in->meter / METER_PER_INCH;

if (in->imperial.inch >= 0

&& in->imperial.inch/36 < LONG_MAX)

{

in->imperial.yard = in->imperial.inch/36;

in->imperial.inch -= in->imperial.yard*36.0;

in->imperial.foot = in->imperial.inch/12;

in->imperial.inch -= in->imperial.foot*12.0;

}

else {

in->imperial.yard = in->imperial.foot = 0;

}

}

void print_metric_imp (metric_imp *in)

{

printf("\n Meter %g is = %ld yards %d feet"

" %g inches\n",

in->meter, in->imperial.yard,

(int)in->imperial.foot, in->imperial.inch);

}

int do_another (void)

{

int answer;

printf("\n Do you want to proceed (y/n)? ");

fflush(stdout);

answer = getchar();

cleanup_stdin();

return EOF != answer && 'y' == tolower(answer);

}

--

E-Mail: Mine is an /at/ gmx /dot/ de address.