能否帮我说明一下

来源:百度知道 编辑:UC知道 时间:2024/05/14 14:45:14
#define SIZE 6
#include "stdio.h"
void main()
{
int i,code;
float taxi[SIZE+1],fee;
for(i=1;i<=SIZE;i++)
taxi[i]=0;
printf("Please input code and fee:");
scanf("%d%f",&code,&fee);
while(code>=1&&code<=6)
{
taxi[code]=taxi[code]+fee;
printf("Please input code and fee:");
scanf("%d%f",&code,&fee);
}
printf("code fee\n",i,taxi[i]);
for(i=1;i<=SIZE;i++)
printf("%3d %10.2f\n",i,taxi[i]);
}

提问: float taxi[SIZE+1],fee;
为什么taxi[SIZE+1]
什么意思?能否解释详细一些

float taxi[SIZE]是定义一个长度为6的数组,数组中taxi[0]~taxi[5]都是可用的。

但现在的程序中float taxi[SIZE+1]定义了一个长度为7的数组,数组中包含数组中taxi[0]~taxi[6]这7个可用变量。作者没有使用taxi[0],原因不详。

应该说,程序的作者是个菜鸟,这样的程序让人感觉别扭。
#include "stdio.h" 中的引号也用得不对

while(code>=1&&code<=6)
{
taxi[code]=taxi[code]+fee;
printf("Please input code and fee:");
scanf("%d%f",&code,&fee);
}
因为这里的code这里的要求是1到6之间的,如果定义时用的是float taxi[SIZE],那么数组是taxi[0]到taxi[5],如果用taxi[SIZE+1],就可以使这个程序更“傻瓜”更好用点,注意这里taxi[0]就没有用它了

如果,我说的又点道理,分给我吧~谢谢咯