所以它是一个星期五,我一直在使用这个应用程序,我的头快要爆炸了。我在任何地方都找不到问题!!!我是初学者,所以我希望 stackoverflow 的大神可以指导我正确的方向或提供一些反馈!:]
这个控制台应用程序只是一张简单的停车时间票。代码符合正常,没有错误。但是我的数学一团糟!
这是一个示例结果:时间输入为 3:50,出口为 5:29,车辆为 T。
TIME-IN -858993460:858993460
TIME-OUT -858933460:-858993460
PARKING TIME 0:-858993460
TOTAL CHARGE -214748352.00
这是我的代码
#include <iostream> //used for cout/cin
#include <iomanip> //used to manipulate data
void getData(int* ehour, int* emin, int* exhour, int* exmin);
void rate(int exhour, int exmin, int ehour, int emin, int* thour, int* tmin, int* round);
void charge(char* vehic, float* rate1, float* rate2, int ehour);
void result(int exhour, int exmin, int ehour, int emin, int thour, float rate1, float rate2, int round, float total);
int main(void)
{
char vehic;
int ehour;
int emin;
int exhour;
int exmin;
int thour;
int tmin;
int round;
float rate1;
float rate2;
float total;
getData(&ehour, &emin, &exhour, &exmin);
rate(exhour, exmin, ehour, emin, &thour, &tmin, &round);
charge(&vehic, &rate1, &rate2, ehour);
total= rate1 + rate2;
result( exhour, exmin, ehour, emin, thour, rate1, rate2, round, total);
return 0;
}
void getData(int* ehour, int* emin, int* exhour, int* exmin)
{
char v;
printf("Enter C for car, B for bus, T for truck: ");
scanf("%c", &v);
printf("\nHour vehicle entered 0-24: ");
scanf("%d", &ehour);
printf("\nMinute vehicle entered 0-60: ");
scanf("%d", &emin);
printf("\nHour vehicle exited 0-24: ");
scanf("%d", &exhour);
printf("\nMinute vehicle exited 0-60: ");
scanf("%d", &exmin);
return;
}
void rate(int exhour, int exmin, int ehour, int emin, int* thour, int* tmin, int* round)
{
if(emin < exmin)
{
emin= emin + 60;
exhour= exhour - 1;
}
*thour = ehour - exhour;
*tmin = emin - exmin;
if ((*tmin > 0 && *tmin <= 60))
{
*thour = *thour + 1;
*round = *tmin * 0;
}
return;
}
void charge(char* vehic, float* rate1, float* rate2, int ehour)
{
switch (*vehic)
{
case 'c': if (ehour <= 3)
{
*rate1 = 0.00;
if (ehour > 3)
*rate2 = 1.25 * (ehour - 3);
}
break;
case 'b': if (ehour <= 2)
{
*rate1 = 2.00 * ehour;
if (ehour > 2)
*rate2 = 2.50 * (ehour - 2);
}
break;
case 't': if (ehour <= 1)
{
*rate1 = 3.75 * ehour;
if (ehour > 1)
*rate2 = 4.50 * (ehour - 1);
}
break;
}
return;
}
void result(int exhour, int exmin, int ehour, int emin, int thour, float rate1, float rate2, int round, float total)
{
printf("\n\t\t PARKING LOT CHARGE \t\t\n");
printf("\nType of vehicle: Car or Bus or Truck");
printf("\nTIME-IN\t\t %d:%d", ehour, emin);
printf("\nTIME-OUT\t\t %d:%d", exhour, exmin);
printf("\n\t\t\t --------");
printf("\nPARKING TIME\t\t %d:%d", thour, round);
printf("\n\t\t\t --------");
total= rate1 + rate2;
printf("\nTOTAL CHARGE\t\t %4.2f\n\n", total);
return;
}
对不起,这是很多代码!我简直太疑惑了!!!我的整数格式不正确吗?数学错了吗?