【发布时间】:2015-07-30 13:45:49
【问题描述】:
我很原始,我写了很多基本程序。我的新日程安排程序有问题。我想计算总公园食谱并在屏幕上写上车号和小时数。此序列必须是车时收费。 在我的程序中,只有 scanf() 向用户询问小时。用户写小时并输入,程序换行。我想这样输出
Car Hours Charge
1 5 3.00
但是程序输出是这样的
Car Hours Charge
1 5
3.00
这是我的程序源代码:
#include<stdio.h>
double calculateCharges ( double time1 );
int main( void )
{ //open main
double time;
int i;
double TotalCharges=0, TotalTime=0;
printf("Car\tHours\tCharge\t\n");
for(i=1;i<=3;i++) //there is 3 cars checkin
{ //open for
printf("%d\t",i);
scanf("%lf", &time);
printf("\t");
TotalTime+=time;
printf("%lf",calculateCharges(time) ); // fonks calculate
TotalCharges+=calculateCharges(time); // for total charge
puts("");
} // end for
} // end main
double calculateCharges ( double time1 )
{ //open fonk
double totalC=0;
if( time1<=3) // untill 3 hours, for 2 dolars
{ //open if
totalC+=2.00;
} //end if
else if(time1>3) // after 3 hours, each hours cost 0.5 dolars
{ //open else if
totalC+=2+(time1-3)*0.5;
} //end else if
return totalC;
} // end fonk
【问题讨论】:
-
如果我将
printf("\t");更改为printf("%lf\t", time);对我来说效果很好 -
其实我是初学者,不知道这段代码怎么写。请解释一下,也有一些简单的解决方案。
-
我没有得到你所说的输出。你的意见是什么?
-
t_thirupathi 不幸的是它不起作用。如果我这样做,程序会得到新行并再次写入小时数,并且在充电和输出之间没有相同的线 fonks
-
好的,现在我明白你的问题了。如果您担心终端上的输出,可以将输出写入变量/文件并在所有处理后输出。
标签: c