标题:实习的题目 为什么这个会陷入死循环 大家帮忙改下吧
只看楼主
曾小泽
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2008-8-29
 问题点数:0 回复次数:7 
实习的题目 为什么这个会陷入死循环 大家帮忙改下吧
实验设备管理系统设计
要求

实验设备信息包括:设备编号,设备种类(如:微机,打印机,扫描仪等等),设备名称,设备价格,设备购入日期,是否报废,报废日期等。试设计一实验设备信息管理系统,使之能提供以下功能:

1能够完成对设备的录入和修改

2对设备进行分类统计

3设备的查询


#include <stdio.h>
#include <string.h>
struct instrument
{
char p_num[12];
char name[12];
char spec[12];
int amount;
int price;
int s_price;
struct instrument *next;
};
struct instrument *head;
struct in_instrument
{
char num[12];
char p_num[12];
char name[12];
int amount;
int price;
int t_price;
struct in_instrument *next;
};
struct in_instrument *ihead;
struct out_instrument
{
char num[12];
char p_num[12];
char name[12];
int amount;
int price;
int t_price;
struct out_instrument *next;
};
struct out_instrument *ohead;
struct quit_instrument
{
char num[12];
char p_num[12];
char name[12];
int amount;
int price;
int t_price;
struct quit_instrument *next;
};
struct quit_instrument *qhead;
int init()
{
head=ihead=ohead=qhead=NULL;
printf("0: Quit\n");
printf("1: Enter the information of in instrument\n");
printf("2: Enter the information of out instrument\n");
printf("3: Enter the information of quit instrument\n");
printf("4: Total the information of instrument\n");
}
int menu()
{
printf("1:insert data\n");
printf("2:delete data\n");
printf("3:modify data\n");
printf("4:select data\n");
printf("Other to quit\n");
}
int menu2()
{
printf("0: Quit\n");
printf("1: Enter the information of in instrument\n");
printf("2: Enter the information of out instrument\n");
printf("3: Enter the information of quit instrument\n");
printf("4: Total the information of instrument\n");
}
int insert_instrument()
{
struct instrument * p1,* p;
p1=(struct instrument *)malloc(sizeof(struct instrument));
p=head;
if (p==NULL)
{
printf("Enter the data of instrument\n");
printf("Include the spbh,name,style,num,price,sale_price of instrument\n");
scanf("%s%s%s%d%d%d",
&p1->p_num,&p1->name,&p1->spec,&p1->amount,&p1->price,&p1->s_price);
head=p1;
head->next=NULL;
return 0;
}
while(p->next!=NULL)
p=p->next;
p->next=p1;
printf("Enter the data\n");
scanf("%s%s%s%d%d%d",
&p1->num,&p1->p_num,&p1->name,&p1->amount,&p1->price,&p1->t_price);
p1->next=NULL;
}
int in_insert()
{
struct in_instrument * p1,* p;
p1=(struct in_instrument *)malloc(sizeof(struct in_instrument));
p=ihead;
if (p==NULL)
{
printf("Enter the data of in instrument\n");
printf("Include the rkbh,spbh,name,number,price,total_price\n");
scanf("%s%s%s%d%d%d",
&p1->num,&p1->p_num,&p1->name,&p1->amount,&p1->price,&p1->t_price);
ihead=p1;
ihead->next=NULL;
return 0;
}
while(p->next!=NULL)
p=p->next;
p->next=p1;
printf("Enter the data\n");
scanf("%s%s%s%d%d%d",
&p1->num,&p1->p_num,&p1->name,&p1->amount,&p1->price,&p1->t_price);
p1->next=NULL;
}
int in_modify()
{
char m_num[12];
struct in_instrument * p;
p=ihead;
printf("Enter the modify num\n");
scanf("%s",&m_num);
if (p==NULL)
{
printf("Sorry! No data can be found\n");
return 0;
}
while(p!=NULL)
{
if (strcmp(p->num,m_num)==0)
{
printf("Enter the new data without num\n");
scanf("%s%s%d%d%d",
&p->p_num,&p->name,&p->amount,&p->price,&p->t_price);
printf("One data had modified\n");
return 0;
}
p=p->next;
}
printf("Sorry! No num has found\n");
}
int in_select()
{
char s_num[12];
struct in_instrument * p;
p=ihead;
printf("Enter the select num\n");
scanf("%s",&s_num);
while(p!=NULL)
{
if (strcmp(p->num,s_num)==0)
{
printf("The data you want is:\n");
printf(" %s %s %s %d %d %d\n",
p->num,p->p_num,p->name,p->amount,p->price,p->t_price);
return 0;
}
p=p->next;
}
printf("Sorry! No num has found\n");
}

int in_delete()
{
char d_num[12];
struct in_instrument * p1,* p;
p=ihead;
printf("Enter the delete num\n");
scanf("%s",&d_num);
if (p==NULL)
{
printf("No data can be found\n");
return 0;
}
if (strcmp(p->num,d_num)==0 && p->next==NULL)
{
ihead=NULL;
printf("One data has been deleted\n");
return 0;
}
if (strcmp(p->num,d_num)==0 && p->next!=NULL)
{
ihead=ihead->next;
printf("One data has been deleted\n");
return 0;
}
while(p->next!=NULL)
{
p1=p->next;
if (strcmp(p1->num,d_num)==0)
{
p->next=p1->next;
printf("One data has been deleted\n");
return 0;
}
p=p->next;
}
printf("Sorry! No num has found\n");
}
int out_insert()
{
struct out_instrument * p1,* p;
p1=(struct out_instrument *)malloc(sizeof(struct out_instrument));
p=ohead;
if (p==NULL)
{
printf("Enter the data of out instrument\n");
printf("Include the ckbh,spbh,name,number,price,total_price\n");
scanf("%s%s%s%d%d%d",
&p1->num,&p1->p_num,&p1->name,&p1->amount,&p1->price,&p1->t_price);
ohead=p1;
ohead->next=NULL;
return 0;
}
while(p->next!=NULL)
p=p->next;
p->next=p1;
printf("Enter the data\n");
scanf("%s%s%s%d%d%d",
&p1->num,&p1->p_num,&p1->name,&p1->amount,&p1->price,&p1->t_price);
p1->next=NULL;
}
int out_modify()
{
char m_num[12];
struct out_instrument * p;
p=ohead;
printf("Enter the modify num\n");
scanf("%s",&m_num);
if (p==NULL)
{
printf("Sorry! No data can be found\n");
return 0;
}
while(p!=NULL)
{
if (strcmp(p->num,m_num)==0)
{
printf("Enter the new data without num\n");
scanf("%s%s%d%d%d",
&p->p_num,&p->name,&p->amount,&p->price,&p->t_price);
printf("One data had modified\n");
return 0;
}
p=p->next;
}
printf("Sorry! No num has found\n");
}
int out_select()
{
char s_num[12];
struct out_instrument * p;
p=ohead;
printf("Enter the select num\n");
scanf("%s",&s_num);
while(p!=NULL)
{
if (strcmp(s_num,p->num)==0)
{
printf("The data you want is:\n");
printf(" %s %s %s %d %d %d\n",
p->num,p->p_num,p->name,p->amount,p->price,p->t_price);
return 0;
}
p=p->next;
}
printf("Sorry! No num has found\n");
}
int out_delete()
{
char d_num[12];
struct out_instrument * p1,* p;
p=ohead;
printf("Enter the delete num\n");
scanf("%s",&d_num);
if (p==NULL)
{
printf("No data can be found\n");
return 0;
}
if (strcmp(p->num,d_num)==0 && p->next==NULL)
{
ohead=NULL;
printf("One data has been deleted\n");
return 0;
}
if (strcmp(p->num,d_num)==0 && p->next!=NULL)
{
ohead=ohead->next;
printf("One data has been deleted\n");
return 0;
}
while(p->next!=NULL)
{
p1=p->next;
if (strcmp(p1->num,d_num)==0)
{
p->next=p1->next;
printf("One data has been deleted\n");
return 0;
}
p=p->next;
}
printf("Sorry! No num has found\n");
}
int quit_insert()
{
struct quit_instrument * p1,* p;
p1=(struct quit_instrument *)malloc(sizeof(struct quit_instrument));
p=qhead;
if (p==NULL)
{
printf("Enter the data of quit instrument\n");
printf("Include the thbh,spbh,name,number,price,total_price\n");
scanf("%s%s%s%d%d%d",
&p1->num,&p1->p_num,&p1->name,&p1->amount,&p1->price,&p1->t_price);
qhead=p1;
qhead->next=NULL;
return 0;
}
while(p->next!=NULL)
p=p->next;
p->next=p1;
printf("Enter the data\n");
scanf("%s%s%s%d%d%d",
&p1->num,&p1->p_num,&p1->name,&p1->amount,&p1->price,&p1->t_price);
p1->next=NULL;
}
int quit_modify()
{
char m_num[12];
struct quit_instrument * p;
p=qhead;
printf("Enter the modify num\n");
scanf("%s",&m_num);
if (p==NULL)
{
printf("Sorry! No data can be found\n");
return 0;
}
while(p!=NULL)
{
if (strcmp(p->num,m_num)==0)
{
printf("Enter the new data without num\n");
scanf("%s%s%d%d%d",
&p->p_num,&p->name,&p->amount,&p->price,&p->t_price);
printf("One data had modified\n");
return 0;
}
p=p->next;
}
printf("Sorry! No num has found\n");
}
int quit_select()
{
char s_num[12];
struct quit_instrument * p;
p=qhead;
printf("Enter the select num\n");
scanf("%s",&s_num);
while(p!=NULL)
{
if (strcmp(s_num,p->num)==0)
{
printf("The data you want is:\n");
printf(" %s %s %s %d %d %d\n",
p->num,p->p_num,p->name,p->amount,p->price,p->t_price);
return 0;
}
p=p->next;
}
printf("Sorry! No num has found\n");
}
int quit_delete()
{
char d_num[12];
struct quit_instrument * p1,* p;
p=qhead;
printf("Enter the delete num\n");
scanf("%s",&d_num);
if (p==NULL)
{
printf("No data can be found\n");
return 0;
}
if (strcmp(p->num,d_num)==0 && p->next==NULL)
{
qhead=NULL;
printf("One data has been deleted\n");
return 0;
}
if (strcmp(p->num,d_num)==0 && p->next!=NULL)
{
qhead=qhead->next;
printf("One data has been deleted\n");
return 0;
}
while(p->next!=NULL)
{
p1=p->next;
if (strcmp(p1->num,d_num)==0)
{
p->next=p1->next;
printf("One data has been deleted\n");
return 0;
}
p=p->next;
}
printf("Sorry! No num has found\n");
}
int total()
{
int in_num=0,in_price=0;
int out_num=0,out_price=0;
int num=0,price=0;
struct in_instrument *ip;
struct out_instrument *op;
struct instrument *p;
ip=ihead;
while(ip!=NULL)
{
in_num+=ip->amount;
in_price+=ip->t_price;
ip=ip->next;
}
op=ohead;
while(op!=NULL)
{
out_num+=op->amount;
out_price+=op->t_price;
op=op->next;
}
p=head;
while(p!=NULL)
{
num+=p->amount;
price+=p->s_price;
p=p->next;
}
printf("The in instrument's total number and total price is:\n");
printf("%d %d\n",in_num,in_price);
printf("The out instrument's total number and total price is:\n");
printf("%d %d\n",out_num,out_price);
printf("The instrument's total number and total price is:\n");
printf("%d %d\n",num,price);
}
int in_case()
{
int choice;
printf("The information of in instrument:\n");
while(1)
{
printf("Enter the choice\n");
scanf("%d",&choice);
switch(choice)
{
case 1: in_insert();insert_instrument();break;
case 2: in_delete();break;
case 3: in_modify();break;
case 4: in_select();break;
default: return 0;
}
menu();
}
}
int out_case()
{
int choice;
printf("The information of out instrument:\n");
while(1)
{
printf("Enter the choice\n");
scanf("%d",&choice);
switch(choice)
{
case 1: out_insert();break;
case 2: out_delete();break;
case 3: out_modify();break;
case 4: out_select();break;
default:return 0;
}
menu();
}
}
int quit_case()
{
int choice;
printf("The information of quit instrument:\n");
while(1)
{
printf("Enter the choice\n");
scanf("%d",&choice);
switch(choice)
{
case 1: quit_insert();break;
case 2: quit_delete();break;
case 3: quit_modify();break;
case 4: quit_select();break;
default: return 0;
}
menu();
}
}
int main()
{
int choice;
init();
while(1)
{
scanf("%d",&choice);
switch(choice)
{
case 0: return 0;
case 1: menu();in_case(); break;
case 2: menu();out_case();break;
case 3: menu();quit_case();break;
case 4:total();break;
}
menu2();
}
}
搜索更多相关主题的帖子: 实习 
2008-08-29 19:51
flyue
Rank: 10Rank: 10Rank: 10
来 自:江南西道
等 级:贵宾
威 望:19
帖 子:3465
专家分:1563
注 册:2006-6-20
得分:0 

天之道,损有余而补不足.人之道则不然,损不足以奉有余.孰能有余以奉天下,唯有道者.
2008-08-29 19:56
liyanhong
Rank: 3Rank: 3
来 自:水星
等 级:禁止访问
威 望:8
帖 子:1867
专家分:0
注 册:2008-5-3
得分:0 

爱上你 是 我的错  可是离 开  又舍不得  听着你为我写的歌     好难过
如果说 我说如果  我们还 能  重新来过   不去计 较 谁对谁错  会怎么做
2008-08-29 21:12
ONEPROBLEM
Rank: 6Rank: 6
来 自:广西 南宁
等 级:贵宾
威 望:21
帖 子:1569
专家分:349
注 册:2008-7-11
得分:0 
LZ啊,程序太长了~~既没有注释,也没有一定的缩进,大家哪里看得下去呀?
建议,重新编辑,做好注释及缩进,方便大家阅读,并提意见~~
2008-08-29 22:06
xmnathan
Rank: 2
等 级:论坛游民
威 望:1
帖 子:73
专家分:10
注 册:2008-8-30
得分:0 
函数有几个都看不出来 怎么看得进去哈
2008-08-30 10:07
無邪的睡脸
Rank: 2
等 级:等待验证会员
威 望:1
帖 子:344
专家分:13
注 册:2007-9-11
得分:0 
有人愿意帮你看,我真算是佩服了!
2008-08-30 10:20
flyue
Rank: 10Rank: 10Rank: 10
来 自:江南西道
等 级:贵宾
威 望:19
帖 子:3465
专家分:1563
注 册:2006-6-20
得分:0 
整理了一下

#include <stdio.h>
#include <string.h>

struct instrument
{
    char p_num[12];
    char name[12];
    char spec[12];
    int amount;
    int price;
    int s_price;
    struct instrument *next;
};

struct instrument *head;

struct in_instrument
{
    char num[12];
    char p_num[12];
    char name[12];
    int amount;
    int price;
    int t_price;
    struct in_instrument *next;
};

struct in_instrument *ihead;

struct out_instrument
{
    char num[12];
    char p_num[12];
    char name[12];
    int amount;
    int price;
    int t_price;
    struct out_instrument *next;
};

struct out_instrument *ohead;

struct quit_instrument
{
    char num[12];
    char p_num[12];
    char name[12];
    int amount;
    int price;
    int t_price;
    struct quit_instrument *next;
};

struct quit_instrument *qhead;

int init()
{
    head=ihead=ohead=qhead=NULL;
    printf("0: Quit\n");
    printf("1: Enter the information of in instrument\n");
    printf("2: Enter the information of out instrument\n");
    printf("3: Enter the information of quit instrument\n");
    printf("4: Total the information of instrument\n");
}

int menu()
{
    printf("1:insert data\n");
    printf("2:delete data\n");
    printf("3:modify data\n");
    printf("4:select data\n");
    printf("Other to quit\n");
}

int menu2()
{
    printf("0: Quit\n");
    printf("1: Enter the information of in instrument\n");
    printf("2: Enter the information of out instrument\n");
    printf("3: Enter the information of quit instrument\n");
    printf("4: Total the information of instrument\n");
}

int insert_instrument()
{
    struct instrument * p1,* p;
    
    p1=(struct instrument *)malloc(sizeof(struct instrument));
    p=head;
    
    if (p==NULL)
    {
        printf("Enter the data of instrument\n");
        printf("Include the spbh,name,style,num,price,sale_price of instrument\n");
        scanf("%s%s%s%d%d%d",
            &p1->p_num,&p1->name,&p1->spec,&p1->amount,&p1->price,&p1->s_price);
        head=p1;
        head->next=NULL;
        return 0;
    }
    
    while(p->next!=NULL)
        p=p->next;
    
    p->next=p1;
    printf("Enter the data\n");
    scanf("%s%s%s%d%d%d", &p1->num,&p1->p_num,&p1->name,&p1->amount,&p1->price,&p1->t_price);
    p1->next=NULL;
}

int in_insert()
{
    struct in_instrument * p1,* p;
    p1=(struct in_instrument *)malloc(sizeof(struct in_instrument));
    p=ihead;
    
    if (p==NULL)
    {
        printf("Enter the data of in instrument\n");
        printf("Include the rkbh,spbh,name,number,price,total_price\n");
        scanf("%s%s%s%d%d%d",
            &p1->num,&p1->p_num,&p1->name,&p1->amount,&p1->price,&p1->t_price);
        ihead=p1;
        ihead->next=NULL;
        return 0;
    }
    
    while(p->next!=NULL)
        p=p->next;
    
    p->next=p1;
    printf("Enter the data\n");
    scanf("%s%s%s%d%d%d", &p1->num,&p1->p_num,&p1->name,&p1->amount,&p1->price,&p1->t_price);
    p1->next=NULL;
}

int in_modify()
{
    char m_num[12];
    struct in_instrument * p;
    p=ihead;
    printf("Enter the modify num\n");
    scanf("%s",&m_num);
    
    if (p==NULL)
    {
        printf("Sorry! No data can be found\n");
        return 0;
    }
    
    while(p!=NULL)
    {
        if (strcmp(p->num,m_num)==0)
        {
            printf("Enter the new data without num\n");
            scanf("%s%s%d%d%d",
                &p->p_num,&p->name,&p->amount,&p->price,&p->t_price);
            printf("One data had modified\n");
            return 0;
        }
        p=p->next;
    }
    
    printf("Sorry! No num has found\n");
}


int in_select()
{
    char s_num[12];
    struct in_instrument * p;
    p=ihead;
    printf("Enter the select num\n");
    scanf("%s",&s_num);
    
    while(p!=NULL)
    {
        if (strcmp(p->num,s_num)==0)
        {
            printf("The data you want is:\n");
            printf(" %s %s %s %d %d %d\n",
                p->num,p->p_num,p->name,p->amount,p->price,p->t_price);
            return 0;
        }
        p=p->next;
    }
    
    printf("Sorry! No num has found\n");
}


int in_delete()
{
    char d_num[12];
    struct in_instrument * p1,* p;
    p=ihead;
    printf("Enter the delete num\n");
    scanf("%s",&d_num);
    
    if (p==NULL)
    {
        printf("No data can be found\n");
        return 0;
    }
    
    if (strcmp(p->num,d_num)==0 && p->next==NULL)
    {
        ihead=NULL;
        printf("One data has been deleted\n");
        return 0;
    }
    
    if (strcmp(p->num,d_num)==0 && p->next!=NULL)
    {
        ihead=ihead->next;
        printf("One data has been deleted\n");
        return 0;
    }
    
    while(p->next!=NULL)
    {
        p1=p->next;
        if (strcmp(p1->num,d_num)==0)
        {
            p->next=p1->next;
            printf("One data has been deleted\n");
            return 0;
        }
        p=p->next;
    }
    
    printf("Sorry! No num has found\n");
}


int out_insert()
{
    struct out_instrument * p1,* p;
    p1=(struct out_instrument *)malloc(sizeof(struct out_instrument));
    p=ohead;
    
    if (p==NULL)
    {
        printf("Enter the data of out instrument\n");
        printf("Include the ckbh,spbh,name,number,price,total_price\n");
        scanf("%s%s%s%d%d%d",
            &p1->num,&p1->p_num,&p1->name,&p1->amount,&p1->price,&p1->t_price);
        ohead=p1;
        ohead->next=NULL;
        return 0;
    }
    
    while(p->next!=NULL)
        p=p->next;
    
    p->next=p1;
    printf("Enter the data\n");
    scanf("%s%s%s%d%d%d", &p1->num,&p1->p_num,&p1->name,&p1->amount,&p1->price,&p1->t_price);
    
    p1->next=NULL;
}


int out_modify()
{
    char m_num[12];
    struct out_instrument * p;
    p=ohead;
    printf("Enter the modify num\n");
    scanf("%s",&m_num);
    
    if (p==NULL)
    {
        printf("Sorry! No data can be found\n");
        return 0;
    }
    
    while(p!=NULL)
    {
        if (strcmp(p->num,m_num)==0)
        {
            printf("Enter the new data without num\n");
            scanf("%s%s%d%d%d",
                &p->p_num,&p->name,&p->amount,&p->price,&p->t_price);
            printf("One data had modified\n");
            return 0;
        }
        p=p->next;
    }
    printf("Sorry! No num has found\n");
}


int out_select()
{
    char s_num[12];
    struct out_instrument * p;
    p=ohead;
    printf("Enter the select num\n");
    scanf("%s",&s_num);
    
    while(p!=NULL)
    {
        if (strcmp(s_num,p->num)==0)
        {
            printf("The data you want is:\n");
            printf(" %s %s %s %d %d %d\n",
                p->num,p->p_num,p->name,p->amount,p->price,p->t_price);
            return 0;
        }
        p=p->next;
    }
    
    printf("Sorry! No num has found\n");
}


int out_delete()
{
    char d_num[12];
    struct out_instrument * p1,* p;
    p=ohead;
    printf("Enter the delete num\n");
    scanf("%s",&d_num);
    
    if (p==NULL)
    {
        printf("No data can be found\n");
        return 0;
    }
    
    if (strcmp(p->num,d_num)==0 && p->next==NULL)
    {
        ohead=NULL;
        printf("One data has been deleted\n");
        return 0;
    }
    
    if (strcmp(p->num,d_num)==0 && p->next!=NULL)
    {
        ohead=ohead->next;
        printf("One data has been deleted\n");
        return 0;
    }
    
    while(p->next!=NULL)
    {
        p1=p->next;
        if (strcmp(p1->num,d_num)==0)
        {
            p->next=p1->next;
            printf("One data has been deleted\n");
            return 0;
        }
        p=p->next;
    }
    
    printf("Sorry! No num has found\n");
}


int quit_insert()
{
    struct quit_instrument * p1,* p;
    p1=(struct quit_instrument *)malloc(sizeof(struct quit_instrument));
    p=qhead;
    
    if (p==NULL)
    {
        printf("Enter the data of quit instrument\n");
        printf("Include the thbh,spbh,name,number,price,total_price\n");
        scanf("%s%s%s%d%d%d",
            &p1->num,&p1->p_num,&p1->name,&p1->amount,&p1->price,&p1->t_price);
        qhead=p1;
        qhead->next=NULL;
        return 0;
    }
    
    while(p->next!=NULL)
        p=p->next;
    
    p->next=p1;
    printf("Enter the data\n");
    scanf("%s%s%s%d%d%d",
        &p1->num,&p1->p_num,&p1->name,&p1->amount,&p1->price,&p1->t_price);
    p1->next=NULL;
}


int quit_modify()
{
    char m_num[12];
    struct quit_instrument * p;
    p=qhead;
    printf("Enter the modify num\n");
    scanf("%s",&m_num);
    
    if (p==NULL)
    {
        printf("Sorry! No data can be found\n");
        return 0;
    }
    
    while(p!=NULL)
    {
        if (strcmp(p->num,m_num)==0)
        {
            printf("Enter the new data without num\n");
            scanf("%s%s%d%d%d",
                &p->p_num,&p->name,&p->amount,&p->price,&p->t_price);
            printf("One data had modified\n");
            return 0;
        }
        p=p->next;
    }
    
    printf("Sorry! No num has found\n");
}


int quit_select()
{
    char s_num[12];
    struct quit_instrument * p;
    p=qhead;
    printf("Enter the select num\n");
    scanf("%s",&s_num);
    
    while(p!=NULL)
    {
        if (strcmp(s_num,p->num)==0)
        {
            printf("The data you want is:\n");
            printf(" %s %s %s %d %d %d\n",
                p->num,p->p_num,p->name,p->amount,p->price,p->t_price);
            return 0;
        }
        p=p->next;
    }
    
    printf("Sorry! No num has found\n");
}


int quit_delete()
{
    char d_num[12];
    struct quit_instrument * p1,* p;
    p=qhead;
    printf("Enter the delete num\n");
    scanf("%s",&d_num);
    
    if (p==NULL)
    {
        printf("No data can be found\n");
        return 0;
    }
    
    if (strcmp(p->num,d_num)==0 && p->next==NULL)
    {
        qhead=NULL;
        printf("One data has been deleted\n");
        return 0;
    }
    
    if (strcmp(p->num,d_num)==0 && p->next!=NULL)
    {
        qhead=qhead->next;
        printf("One data has been deleted\n");
        return 0;
    }
    
    while(p->next!=NULL)
    {
        p1=p->next;
        if (strcmp(p1->num,d_num)==0)
        {
            p->next=p1->next;
            printf("One data has been deleted\n");
            return 0;
        }
        p=p->next;
    }
    
    printf("Sorry! No num has found\n");
}


int total()
{
    int in_num=0,in_price=0;
    int out_num=0,out_price=0;
    int num=0,price=0;
    struct in_instrument *ip;
    struct out_instrument *op;
    struct instrument *p;
    ip=ihead;
    
    while(ip!=NULL)
    {
        in_num+=ip->amount;
        in_price+=ip->t_price;
        ip=ip->next;
    }
    
    op=ohead;
    
    while(op!=NULL)
    {
        out_num+=op->amount;
        out_price+=op->t_price;
        op=op->next;
    }
    
    p=head;
    
    while(p!=NULL)
    {
        num+=p->amount;
        price+=p->s_price;
        p=p->next;
    }
    
    printf("The in instrument's total number and total price is:\n");
    printf("%d %d\n",in_num,in_price);
    printf("The out instrument's total number and total price is:\n");
    printf("%d %d\n",out_num,out_price);
    printf("The instrument's total number and total price is:\n");
    printf("%d %d\n",num,price);
}


int in_case()
{
    int choice;
    printf("The information of in instrument:\n");
    
    while(1)
    {
        printf("Enter the choice\n");
        scanf("%d",&choice);
        
        switch(choice)
        {
        case 1: in_insert();insert_instrument();break;
        case 2: in_delete();break;
        case 3: in_modify();break;
        case 4: in_select();break;
        default: return 0;
        }
        
        menu();
        
    }
}

int out_case()
{
    int choice;
    printf("The information of out instrument:\n");
    
    while(1)
    {
        printf("Enter the choice\n");
        scanf("%d",&choice);
        
        switch(choice)
        {
        case 1: out_insert();break;
        case 2: out_delete();break;
        case 3: out_modify();break;
        case 4: out_select();break;
        default:return 0;
        }
        
        menu();
        
    }
}


int quit_case()
{
    int choice;
    printf("The information of quit instrument:\n");
    
    while(1)
    {
        printf("Enter the choice\n");
        scanf("%d",&choice);
        
        switch(choice)
        {
        case 1: quit_insert();break;
        case 2: quit_delete();break;
        case 3: quit_modify();break;
        case 4: quit_select();break;
        default: return 0;
        }
        
        menu();
        
    }
}


int main()
{
    int choice;
    init();
    
    while(1)
    {
        scanf("%d",&choice);
        
        switch(choice)
        {
        case 0: return 0;
        case 1: menu();in_case(); break;
        case 2: menu();out_case();break;
        case 3: menu();quit_case();break;
        case 4:total();break;
        }
        
        menu2();

天之道,损有余而补不足.人之道则不然,损不足以奉有余.孰能有余以奉天下,唯有道者.
2008-08-30 10:26
wNumberOney
Rank: 1
等 级:新手上路
帖 子:25
专家分:0
注 册:2008-7-12
得分:0 
这么长,看得头晕啊!
2008-08-30 12:23



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-230484-1-1.html




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

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