void app()
{
printf("输入信闷顾客付款:")
scanf("%d",&guestpay)
if(price==guestpay)
{
printf("交易成功!")
}else if(guestpay>price)
{
change=guestpay-price
printf("找给顾客%d,交易成功!",change)
}else
{
printf("付款枯明不足,交易失败!\n"滑败弯)
app()
}
}
int main()
{
printf("输入价格:")
scanf("%d",&price)
app()
system("pause")
return 0
}
//以下是参考御郑悄代码有相似结构,数据结构自己设丛乱计一下。//如果没参考价值,手下留情,别点不采纳。
#define MAXPARKINGPOS 100
#define MAXPRICETYPE 3
#define MAXLINE 4096
struct detail
{
char num[MAXLINE]
char name[MAXLINE]
double pricePerHour
time_t start
time_t end
double period
double cost
}
static int currentParkingNum = 0
static struct detail detailBuf[MAXPARKINGPOS]
static double priceBuf[MAXPRICETYPE] = {11.0,22.0,33.0}
int main(void) {
char buf[MAXLINE]
struct detail *myParking
int iChoice,leavingIndex,i,numEexisted
struct tm *begin,*end
while(true) {
selectService:
printf("Service type,what is your choice?\n1.park\n2.leave\n3.exit\n")
gets(buf)
if(strcmp(buf,"3") == 0) {
return 0
}
if(strcmp(buf,"1"镇渣) == 0) {
//park
if(currentParkingNum == MAXPARKINGPOS) {
printf("Sorry,not empty!\n\n")
continue
}
myParking = detailBuf+currentParkingNum
printf("your name:\n")
gets(myParking->name)
printf("your parking num:\n")
gets(myParking->num)
numEexisted = 0
for(i=0i<currentParkingNumi++) {
if(strcmp(detailBuf[i].num,myParking->num) == 0) {
numEexisted =1
break
}
}
if(numEexisted != 0) {
printf("The car %s is in\n\n",myParking->num)
goto selectService
}
selectPrice:
printf("Service cost,what is your choice?\n")
for(int i=0i < MAXPRICETYPE i++) {
printf("%d.$%.2f per hour\n",i+1,priceBuf[i])
}
gets(buf)
iChoice = atoi(buf)
if(!(iChoice >= 1 && iChoice <=MAXPRICETYPE)) {
printf("Your choice is incorrect!\n\n")
goto selectPrice
}
myParking->pricePerHour=priceBuf[iChoice-1]
time(&myParking->start)
currentParkingNum++
printf("Parcking ok!\n\n")
}else if(strcmp(buf,"2") == 0) {
//leave
printf("your parking num:\n")
gets(buf)
myParking = NULL
for(i=0i<currentParkingNumi++) {
if(strcmp(detailBuf[i].num,buf) == 0) {
myParking = &detailBuf[i]
leavingIndex = i
break
}
}
if(myParking ==NULL) {
printf("Cannot find your car!\n\n")
continue
}
myParking->end = time(&myParking->end)
myParking->period = difftime(myParking->end,myParking->start)
myParking->cost= myParking->period/3600.0*myParking->pricePerHour
printf("****** Cost Details ******\n")
printf("name:%s\n",myParking->name)
printf("number:%s\n",myParking->num)
printf("price:%.2f\n",myParking->pricePerHour)
begin = localtime(&myParking->start)
strftime(buf,sizeof(buf),"%Y-%m-%d %H:%M:%S",begin)
printf("begin:%s\n",buf)
end = localtime(&myParking->end)
strftime(buf,sizeof(buf),"%Y-%m-%d %H:%M:%S",end)
printf("end:%s\n",buf)
printf("period:%.2f hour(s)\n",myParking->period/3600.0)
printf("cost:$%.2f\n",myParking->cost)
printf("service:$%.2f per hour\n",myParking->pricePerHour)
for(i = leavingIndex i < currentParkingNumi++) {
if(i+1 < currentParkingNum) {
detailBuf[i]=detailBuf[i+1]
}
}
detailBuf[currentParkingNum-1].cost=0.0
detailBuf[currentParkingNum-1].end=0
detailBuf[currentParkingNum-1].name[0]='\0'
detailBuf[currentParkingNum-1].num[0]='\0'
detailBuf[currentParkingNum-1].period=0.0
detailBuf[currentParkingNum-1].pricePerHour=0.0
detailBuf[currentParkingNum-1].start=0
currentParkingNum--
printf("Leaving ok!\n\n")
}else{
printf("Your choice is incorrect!\n\n")
continue
}
}
return 0
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)