| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 590 人关注过本帖
标题:[求助]程序死循环。帮改一下。谢谢
取消只看楼主 加入收藏
l9928299
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2005-12-19
收藏
 问题点数:0 回复次数:1 
[求助]程序死循环。帮改一下。谢谢

#include "graphics.h"
#include <malloc.h>
#include "time.h"
#include "stdio.h"
#define M 10000
#define MAXNUM 1000
#define NIL 0


typedef struct SLNode
{
int Data;
struct SLNode *Next;
} slnodetype;

typedef struct /* 定义带头结点队列链表*/
{ slnodetype *Head;
slnodetype *Rear;

} slqtype;


int bankmoney=M;

int InitiateSLQueue(slqtype *client);
int AppendSLQueue(slqtype *client, int money);
int DeleteSLQueue(slqtype *client);
int inmoney(int money,int bankmoney);
int takemoney(int money, int bankmoney);


int main()
{ int i=0,n,flag;
slqtype client1,client2;
int money;
double var,avertime,time,time1;
clock_t start,end,begin;


InitiateSLQueue(&client1); /*初始化队列1*/
InitiateSLQueue(&client2); /*初始化队列2*/
printf("Now the bank has 10000 yuan!\n");

loop:
printf("Do you want to input money or take money? input 0 or 1?\n "); /*0为存款,1为取款*/
scanf("%d",&flag);
start=clock();
printf("please input your money.\n");
scanf("%d",&money);
i++;
n=i;
AppendSLQueue(&client1,money); /*进入队列1中*/

if(flag==0) /* 存款程序 */
{
bankmoney=inmoney(money,bankmoney); /*调用存款函数*/
DeleteSLQueue(&client1); /*删除此客户*/
end=clock();
/*time1=time1+(double)(end-start)/18.2;*/
printf("The client takes %6.3f seconds!\n", (double)((end-start)/18.2));
printf("Now the bank has %d yuan.\n",bankmoney);

if(1) /* 如果队列2不为空队列,检查队列2中的有没有满足条件的客户*/
DeleteSLQueue(&client2);
printf("窗口2中的人请稍侯!\n");
goto loop;/*检查完转向询问条件*/


}

if (flag==1) /*取款程序*/
{
if (bankmoney<=money) /*取钱数大于银行数,排到队列2中去*/
{
printf("Now the bank has %d yuan.\n",bankmoney);
printf("Sorry!Now the bank has not enough money,please wait for a moment!\n");
AppendSLQueue(&client2, money);
goto loop; /*转向询问状态*/
}

if(bankmoney>money) /*取钱数小于银行数,直接取钱并删除客户记录*/
{ bankmoney=takemoney(money,bankmoney);
DeleteSLQueue(&client1);
end=clock();
/* time1=time1+(double)(end-start)/18.2;*/

printf("The client takes %6.3f seconds.\n", (double)((end-start)/18.2));
printf("Now the bank has %d yuan.\n",bankmoney);
}
}
goto loop;
return 0;
}

int InitiateSLQueue(slqtype *client) /*初始化队列*/
{
if ((client->Head=(slnodetype *)malloc(sizeof(slnodetype)))==NULL)
{
printf("\ failed!");
return 0;
}
client->Rear=client->Head;
client->Head->Next=NULL;
return 1;
}

int AppendSLQueue(slqtype *client, int money) /*入队列函数*/
{
slnodetype *p;
if((p=(slnodetype *)malloc(sizeof(slnodetype)))==NULL)
{ printf("\n failed!");
return 0;
}

p->Data=money;
p->Next=NULL;
client->Rear->Next=p;
client->Rear=p; /*修改尾指针*/
return 1;
}

int DeleteSLQueue(slqtype *client) /*出队列函数*/
{
slnodetype *p,*s;
if((p=(slnodetype *)malloc(sizeof(slnodetype)))==NULL)
{ printf("\n failed!");
return 0;
}
if((s=(slnodetype *)malloc(sizeof(slnodetype)))==NULL)
{ printf("\n failed!");
return 0;
}
if(client->Head->Next==NULL) return NIL; /*空队列*/

if(client->Head->Next==client->Rear) /*只有一个数据的队列*/
{ p=client->Rear;
free(p);
client->Rear=client->Head;
client->Head->Next=NULL;
}
if(client->Head->Next!=client->Rear) /*多个数据的队列*/
{

for(p=client->Head->Next;p!=client->Rear;p=p->Next) /*队列2中的第一个客户指针给client,检查到最后一个*/
{

if(p->Data<bankmoney) /*客户取款*/
{ bankmoney=takemoney(p->Data,bankmoney); /*调用取款函数*/
s=p;
free(s);
/* end=clock();
time1=time1+(double)(end-start)/18.2;
printf("\1:takes %6.3f seconds.\n", (double)((end-start)/18.2)); */
printf("Now the bank has %d yuan.\n",bankmoney);
}

}

}

}


int inmoney(int money,int bankmoney) /*存款函数*/
{ int a=bankmoney,b=money;
a=a+b;
return(a);
}


int takemoney(int money, int bankmoney) /*取款函数*/
{
int c=bankmoney,d=money;
c=c-d;
return (c);
}


搜索更多相关主题的帖子: include money 
2006-07-06 15:48
l9928299
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2005-12-19
收藏
得分:0 
晕。别光说呀。帮改改呀
2006-07-06 15:58
快速回复:[求助]程序死循环。帮改一下。谢谢
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.032197 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved