| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1012 人关注过本帖, 1 人收藏
标题:飞机订票系统 一直死循环,求大神解决
取消只看楼主 加入收藏
xxyuan
Rank: 1
等 级:新手上路
帖 子:9
专家分:3
注 册:2012-9-14
结帖率:50%
收藏(1)
已结贴  问题点数:20 回复次数:2 
飞机订票系统 一直死循环,求大神解决
#include<stdio.h>
#include<string.h>   
#include<stdlib.h>     
#define N 1000  
struct air         
{
    int num;
    char start[20];
    char over[20];
    char time[10];
    int count;
}s[N];
int i;
int m=0;/*全局变量,计算输入数据数*/
#define PRINT "%d%12s%12s%10s%12d\n",s[i].num,s[i].start,s[i].over,s[i].time,s[i].count

void input();    /*输入信息*/
void print();    /*输出信息*/
void save();     /*保存信息*/
void read();     /*读取信息*/
void search();   /*查找信息*/
void delete();  /*删除信息*/
void buy();    /*订票信息*/
void refund();  /*退票信息*/
void modify();   /*修改信息*/

void main()
{
 
    int j;
   
        printf("                           ★ ***  reserve ticket system ***  ★");
        printf("           

****************************************************************************");
        printf("                     1.Enter plane information      2.Scan plane information    \n  

");
                             
        printf("                     3.Modify plane information     4.Search plane information  \n  

");
                              
        printf("                     5.Delete plane information     6.Buy ticket                \n  

");
                                    
        printf("                     7.Refund ticket            0.Exit                      \n  ");
        printf("  ****************************************************************************\n");

        printf("Please input number 0-7and press ENTER.\n");
        do{
        scanf("%d",&j);

 }while(j<0||j>7);
        switch(j)
       {
            case 1:input();   break;
            case 2:print();   break;
            case 3:modify();  break;
            case 4:search();  break;
            case 5:delete();  break;
            case 6:buy();     break;
            case 7:refund();  break;
            case 0:;           break;
        }
   
printf("Thank you,goodbye!");
}

void input()
{
    int y;
    printf("                  Please input plane informations:\n");
    printf("*****************************************************************************\n");
    for(i=0;i<N;i++)
    {
        printf("Please input the plane number:\n");
        scanf("%d",&s[i].num);
        printf("Please input the upcity:\n");
        scanf("%s",&s[i].start);
        printf("Please input the downcity:\n");
        scanf("%s",&s[i].over);
        printf("Please input the uptime:\n");
        scanf("%s",&s[i].time);
        printf("How many ticket you want:\n");
        scanf("%d",&s[i].count);
        m++;/*统计输入信息个数*/
  
        printf("the %dth information have completed,do you want to continue input the next

information?\n",m);
        printf("YES.....please press 1 and ENTER.\n");
        printf("NO......please press 0 and ENTER.\n");
        scanf("%d",&y);
        if(y==0)
        {
        save();
        print();
        break;
        }
    }
}

void save()
{   
    FILE *fp,*fp1;
    if((fp=fopen("C:\\sun.txt","wb"))==NULL)/*打开文件并判断是否出错*/
    {
    printf("Set up file fail!\n");
    return;
    }
    if((fp1=fopen("C:\\ru.txt","wb"))==NULL)
    {
    printf("Set up file fail,please press any key quit.\n");
    getchar();
    return;
    }
    for(i=0;i<m;i++)
    if(fwrite(&s[i],sizeof(struct air),1,fp)==0)/*向文件写入数据,并判断是否出错*/
    printf("WRONG!\n");
    fprintf(fp1,"%d",m);
    fclose(fp);
    fclose(fp1);
}


void read()
{
    FILE *fp,*fp1;
    if((fp=fopen("C:\\sun.txt","rb"))==NULL)
    {
    printf("Wrong,please check up the file fp,press any key return.\n");
    getchar();
    }
    if((fp1=fopen("C:\\ru.txt","rb"))==NULL)
    {
    printf("Set up file fail!\n");
    getchar();
    return;
    }
    fscanf(fp1,"%d",&m);
    fclose(fp1);
    for(i=0;i<m;i++)
    {
    fread(&s[i],sizeof(struct air),1,fp);/*从文件中读取信息*/
    }
    fclose(fp);
}
void print()
{
    char w[10];
    read();
    printf("Plane_number\t\tupcity\t\tdowncity\t\ttime\t\tthe_number_of_ticket\n");
    for(i=0;i<m;i++)
    {
        printf("PRINT\n");
    }
    printf("Please press any key+ENTER to return last menu:\n");
    scanf("%s",&w);
}
   
void search()
{
    char name1[20];
    char name2[20];
    char ii[10];
    int n,no;
    do
    {
        printf("Please choice the way to search:\n");/*打印查询方式菜单*/
        printf("1......by plane number\n");
        printf("2......by downcity\n");
        printf("3......by upcity and downcity\n");
        printf("0......return\n");
        printf("input number 0-3:\n");
        printf("press else key to return main menu:\n");
        scanf("%d",&n);
        if(n==0)
            break;
        switch(n)
        {
            case 1:
                printf("Please input plane number:\n");
                scanf("%d",&no);
                break;
            case 2:
                printf("Please input downcity:\n");
                printf("%s",&name2);
                break;
            case 3:
                printf("Please input upcity:\n");
                scanf("%s",&name1);
                printf("Please input downcity:\n");
                scanf("%s",&name2);
                break;
        }
        read();
        for(i=0;i<m;i++)
        {
            if(strcmp(s[i].over,name1)==0||strcmp(s[i].over,name2)==0)
            {
                printf("Search plane informotion accomplish.");
                printf("plane_numeber\t\tupcity\t\tdowncity\t\ttime\t\tthe_number_of_ticket\n");
                printf("PRINT\n");
                break;
            }
            if(s[i].num==no)/* 按航班号判断输出条件 */
            {
            printf("Search plane informotion accomplish.");
            printf("plane_numeber\t\tupcity\t\tdowncity\t\ttime\t\tthe_number_of_ticket\n");
            printf("PRINT\n");
            break;
            }
        }
        no=0;/*将航班号赋值为0*/
        printf("Search finish:");
        printf("Do you want to continue?Please input yes or no + ENTER.");
        scanf("%s",&ii);
    }while(strcmp(ii,"yes")==0);
}

void delete()
{
    char name1[20];
    char name2[20];
    char ii[10];
    int no,n;

    do
    {
        printf("Please choice the way of delete:");
        printf("1......by plane number");
        printf("2......by upcity and downcity");
        printf("0......return");
        printf("please input number 0-2 + ENTER:");
        scanf("%d",&n);
        if(n==0)
            break;   
        switch(n)
        {
            case 1:
                printf("Please input plane number:");
                scanf("%d",&no);
                read();
                break;
            case 2:
                printf("Please input upcity:");
                scanf("%s",&name1);
                printf("Please input downcity:");
                scanf("%s",&name2);
                read();
                break;
        }   
        for(i=0;i<m;i++)
        {
            if(s[i].num==no||strcmp(s[i].start,name1)==0&&strcmp(s[i].over,name2)==0)/*判断输入信息是

否存在 */
            {      
                s[i]=s[m-1];
                m--;
            }
        }
        printf("search finish.");
        printf("Delete the plane information,are you sure?");
        printf("Please input yes or no + ENTER.");
        scanf("%s",&ii);
        save();
        if(!strcmp(ii,"yes"))     
        printf("Please press any key to return the last menu.");
        break;
   }while(n==1||n==2||n==0);
 
}
 

 

void buy()
{
    int n;
    char a[10];
    do
    {
        search();
        printf("How many tickets you want?Please input.");
        scanf("%D",&n);
        if(n<0)
        {
        printf("Please input number again.");
        break;
        }
        if(s[i].count!=0&&s[i].count>=n)/* 判断是否出错 */
        {
            s[i].count=s[i].count-n;
            save();
            printf("Buy ticket succeed.");
            break;
        }
        if(s[i].count<n)/* 判断是否出错 */
        {
            printf("Please a useful number you want ticket.");
            break;
        }
        printf("Are you continue? Please input yes or no +ENTER");
        scanf("%s",&a);
    }while(!strcmp(a,"yes"));
}

void refund()
{
    int n;
    char a[10];
    do
    {
        search();
        printf("How many tickets you want to refund?");
        scanf("%d",&n);
        if(n<0)
            printf("Please input a useful number again:");
        scanf("%d",&n);
        s[i].count=s[i].count+n;
        save();
        printf("Refund succeed.");
        printf("Are you continue?Please input yes or no + ENTER.");
        scanf("%s",&a);
    }while(!strcmp(a,"yes"));
    getchar();
}

void modify()
{
    struct modify
    {  
    int no;
    char name1[20];
    char name2[20];
    char time[20];
    int count;
    }mo[1];
    char j[10];
    int n;
    read();
    do
    {
        printf("Please choice the way of modify.\n");
        printf("1.......by plane number");
        printf("2.......by upcity and downcity");
        printf("Please input 1 or 2 + ENTER.\n");
        scanf("%d",&n);
        switch(n)
        {
            case 1:
                    printf("Please input plane number:\n");
                    scanf("%s",&mo[0].no);
                    break;
            case 2:
                    printf("Please input upcity:\n");
                    scanf("%s",&mo[0].name1);
                    printf("Please input downcity:\n");
                    scanf("%s",&mo[0].name2);
                    break;
        }
        for(i=0;i<m;i++)
        {   
            if(strcmp(s[i].over,mo[0].name1)==0&&strcmp(s[i].over,mo[0].name2)==0)/* 判断输出条件 */
            {
                    printf("plane_numeber\t\tupcity\t\tdowncity\t\ttime\t\tthe_number_of_ticket\n");
                    printf("PRINT");
                    break;
            }
            if(s[i].num==mo[0].no)/* 判断输出条件 */
            {  
                    printf("plane_numeber\t\tupcity\t\tdowncity\t\ttime\t\tthe_number_of_ticket\n");
                    printf("PRINT");
                    break;
            }
        }
        mo[0].no=0;            /* 将结构体中的号为零 */
        printf("Please input new plane_number,upcity,downcity,time and the number of_ticket:\n");
        scanf("%s,%s,%s,%s,%s",&mo[0].no,&mo[0].name1,&mo[0].name2,&mo[0].time,&mo[0].count);
        s[i].num=mo[0].no;/* 替换航班号 */
        strcpy(s[i].start,mo[0].name1);/* 替换其始站 */     /*拷贝字符串*/
        strcpy(s[i].over,mo[0].name2);/* 替换终点站 */
        strcpy(s[i].time,mo[0].time);/* 替换时间 */
        s[i].count=mo[0].count;/* 替换机票数 */
        save();
        printf("Modify succeed!Do you want to continue?Please press yes or no + ENTER.\n");
        scanf("%s",&j);
    }while(strcmp(j,"yes")==0);  
 
}



一直死循环   求大神帮忙解决
搜索更多相关主题的帖子: count search include void 信息 
2012-09-14 15:52
xxyuan
Rank: 1
等 级:新手上路
帖 子:9
专家分:3
注 册:2012-9-14
收藏
得分:0 
咋没人来帮忙看下啊
2012-09-14 16:31
xxyuan
Rank: 1
等 级:新手上路
帖 子:9
专家分:3
注 册:2012-9-14
收藏
得分:0 
自己顶
2012-09-14 16:31
快速回复:飞机订票系统 一直死循环,求大神解决
数据加载中...
 
   



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

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