为什么得不到答案呢?
#include<stdio.h>
#include<stdlib.h>
int getOption ();
void getTime (int *ent_hour, int *ent_minute, int *left_hour, int *left_minute);
double calcu_Cfee (int total_hours);
double calcu_Bfee (int total_hours);
double calcu_Tfee (int total_hours);
int calcu_Time (int ent_hour, int ent_minute, int left_hour, int left_minute);
double calcu_Fee (int option, int total_hours);
void print (int ent_hour, int ent_minute, int left_hour, int left_minute);
void main()
{
int ent_hour,ent_minute,left_hour,left_minute;
int total_hours;
double total_Fee;
int option;
option = getOption ();
getTime (&ent_hour, &ent_minute, &left_hour, &left_minute);
print (ent_hour, ent_minute, left_hour, left_minute);
total_hours = calcu_Time (ent_hour, ent_minute, left_hour, left_minute);
printf ("\n");
printf ("ROUNDED TOTAL\t %d\n",total_hours);
total_Fee = calcu_Fee (option,total_hours);
printf ("\t\t--------\n");
printf ("TOTAL CHARGE\t $%d\n",total_Fee);
}
int getOption ()
{
int option;
printf ("\t***************************");
printf("\n\t* MENU *");
printf("\n\t* *");
printf("\n\t* 1. Car *");
printf("\n\t* 2. Bus *");
printf("\n\t* 3. Trunk *");
printf("\n\t* *");
printf("\n\t***************************");
printf("\n\tType of vehicle? ");
scanf("%d",&option);
return option;
}
void getTime (int *ent_hour, int *ent_minute, int *left_hour, int *left_minute)
{
printf ("Hour vehicle entered lot (0 - 24)? ");
scanf ("%d",ent_hour);
printf ("Minute vehicle entered lot (0 - 60)? ");
scanf ("%d",ent_minute);
printf ("Hour vehicle left lot (0 - 24)? ");
scanf ("%d",left_hour);
printf ("Minute vehicle left lot (0 -60)? ");
scanf ("%d",left_minute);
return;
}
void print (int ent_hour, int ent_minute, int left_hour, int left_minute)
{
printf ("\t\tPARKING LOT CHARGE\n\n");
printf ("Type of Car or Bus or Trunk\n");
printf ("TIME-IN %d : %d\n",ent_hour, ent_minute);
printf ("TIME-OUT %d : %d\n",left_hour, left_minute);
printf ("\t\t--------\n");
return;
}
int calcu_Time (int ent_hour, int ent_minute, int left_hour, int left_minute)
{
int park_hours;
int park_minutes;
if (left_minute < ent_minute)
{
left_minute = left_minute + 60;
left_hour = left_hour - 1;
}
park_hours = left_hour - ent_hour;
park_minutes = left_minute - ent_minute;
printf ("PAKING TIME %d:%d\n",park_hours, park_minutes);
if(park_minutes >=30 )
park_hours = park_hours + 1;
return park_hours;
}
double calcu_Cfee (int total_hours)
{
double C_fee;
if(total_hours <= 3)
C_fee = 0.00;
else
C_fee = (total_hours - 3) * 1.50;
return C_fee;
}
double calcu_Bfee (int total_hours)
{
double B_fee;
if(total_hours <= 2)
B_fee = total_hours * 1.00;
else
B_fee = total_hours * 1.00 + (total_hours - 2) * 2.30;
return B_fee;
}
double calcu_Tfee (int total_hours)
{
double T_fee;
if(total_hours <= 1)
T_fee = total_hours * 2.0;
else
T_fee = total_hours * 2.0 + (total_hours - 1);
return T_fee;
}
double calcu_Fee (int option, int total_hours)
{
double Fee;
switch(option)
{
case 1: Fee = calcu_Cfee (total_hours);
break;
case 2: Fee = calcu_Bfee (total_hours);
break;
case 3: Fee = calcu_Tfee (total_hours);
break;
default: ;
}
return Fee;
}
大侠们,帮小弟看看哪里出错了,总是得不到答案呢?用一下数字测试:Car:进入时间12:40 离开时间16:22,其他请大侠们自己用数字测试!
[解决办法]
这种事情还是自己解决的好!
只有这样才能进步。经验就是这样积累起来的。
[解决办法]
5个小时远远不够的.
因为程序的逻辑错误是最难找的.
你只有跟踪程序的每一步(注:有函数就一定要跟踪进函数里面) ,并且观察程序运行的每一步后,每个变量的计算结果是不是和你设计的一样,最后就能知道哪里有问题了.
[解决办法]
- C/C++ code
Type of vehicle? 1Hour vehicle entered lot (0 - 24)? 12Minute vehicle entered lot (0 - 60)? 22Hour vehicle left lot (0 - 24)? 14Minute vehicle left lot (0 -60)? 33 PARKING LOT CHARGEType of Car or Bus or TrunkTIME-IN 12 : 22TIME-OUT 14 : 33 --------PAKING TIME 2:11ROUNDED TOTAL 2 --------TOTAL CHARGE $0
[解决办法]
楼主不描述问题,就是一串代码。谁知道该怎么帮助你。我也和上面的各位一样:楼主自己单步调试去吧。
[解决办法]
调试了下
printf ("TOTAL CHARGE\t $%d\n",total_Fee);
这句不对
printf ("TOTAL CHARGE\t $%f\n",total_Fee);没问题