#include <stdio.h>
void set_mode (int * m,int * history) ;
void get_info(int * d,float * l);
void show_info (int m,int * d,float * l) ;
int main (void)
{
?? ?int mode;
?? ?int distance;
?? ?float liters;
?? ?int history;?
?? ?
?? ?printf ("Enter 0 for metric mode, 1 for US mode: ") ;
?? ?scanf ("%d", &mode);
?? ?if(mode==0 ||mode==1)
?? ??? ?history = mode;
?? ?while (mode >= 0)
?? ?{
?? ??? ?while(getchar()!='\n')
?? ??? ??? ?continue;?
?? ??? ?set_mode (&mode,&history);
?? ??? ?get_info(&distance,&liters) ;
?? ??? ?show_info (mode,&distance,&liters) ;
?? ??? ?printf ("Enter 0 for metric mode, 1 for US mode") ;
?? ??? ?printf (" (-1 to quit) : ") ;
?? ??? ?scanf ("&d",&mode) ;
?? ??? ?while(getchar()!='\n')
?? ??? ??? ?continue;?
?? ?}
?? ?printf ("Done. \n") ;
?? ?return 0 ;
}
void set_mode (int * m,int * history)?
{
?? ?if(*m != -1 && *m != 1 && *m != 0 )
?? ??? ?*m = *history;
}
void get_info(int * d,float * l)
{
?? ?printf("Enter distance traveled in kilometers :");
?? ?scanf ("%d", d);
?? ?printf("Enter fuel consumed in liters:");
?? ?scanf ("%f", l);
}
void show_info (int m,int * d,float * l)?
{
?? ?if(m==0)
?? ??? ?printf("Fuel consumption is %.2f liters per 100 km.\n",( *l / *d )*100);
?? ?else if(m==1)
?? ??? ?printf("Fuel consumption is %.1f miles per gallon.\n",*d / *l);
}