请教一个函数调用 里面的问题
#include <stdio.h>int set_mode(int);
int get_info(void);
void show_info(void);
int x=0;
int main (void)
{
int mode;
printf("Enter 0 for metric mode,1 for US mode: ");
scanf("%d",&mode);
while(mode>=0)
{
set_mode(mode);
get_info();
show_info();
printf("Enter 0 for metric mode,1 for US mode: ");
printf("(-1 to quit): ");
scanf("%d",&mode);
}
printf("Done.\n");
return 0;
}
int set_mode(int a)
{
if(a>1)
{
printf("Invalid mode specified.Mode 1(US) used.\n");
return x=1;
}
if(a==1)
return x=1;
else
return x=0;
}
int get_info(void)
{
float a,b,c,d;
if(x)
{
printf("Enter distance traveled in miles: ");
scanf("%f",&c);
printf("Enter fuel consumed in gallons: ");
scanf("%f",&d);
return 0;
}
else
{
printf("Enter distance traveled in kilometers: ");
scanf("%f",&a);
printf("Enter fuel consumed in liters: ");
scanf("%f",&b);
return 1;
}
}
void show_info(void)
{
if(x)
printf("Fuel consumpt is 13.13 liters per 100 km.\n");
else
printf("Fuel consumpt is 25.4 miles per gallon.\n");
}
好吧 是我自己VC的问题。。。
[ 本帖最后由 esc345 于 2014-2-14 01:12 编辑 ]