标题:超市收银系统的问题
只看楼主
wldnscjf
Rank: 2
等 级:论坛游民
帖 子:20
专家分:14
注 册:2013-1-27
结帖率:100%
已结贴  问题点数:20 回复次数:8 
超市收银系统的问题
程序代码:
# include <stdio.h> //头文件
# include <string.h> //字符串头文件
# include <stdlib.h>

typedef struct in
{
    char id[20];//会员账号
    char key[20];//会员密码
    int sum;//会员积分
    struct in *next;
}member;

struct im//商品信息 以下是私有成员
{
    int id;//商品编号
    char name[50];//商品名称
    int stoct;//商品库存
}goods[1000];

member *registe(member *t);//注册;
void buy();

int main(void)
{
    member *head = (member *)malloc(sizeof(member));
    strcpy(head->id, "0"), strcpy(head->key, "0");//超市管理员
    head->next = NULL;
    int i, a, n, boo=0;
   
    while(1)
    {
        printf("注册会员请按1: \n");
        printf("会员直接登入请按2:\n");
        printf("推出请按0: \n");
        scanf("%d", &a);
        if (a == 0)
            break;
        if (a == 1)
            head = registe(head);
        else if (a == 2)
            boo = login(head);
        if (boo)
            break;       
    }
    if (a && boo==1)
    {
        printf ("尊贵的会员,您登入成功!\n");
        buy();
    }
    printf ("已经安全推出\n");
    return 0;
}
member *registe(member *t)//注册
{
    printf ("现在开始会员注册\n\n");
    char id[20], key[20];
    member *p, *q, *r;
    p = t;
    while(p->next) p = p->next;//寻找链表中最后一个节点
    while(1)
    {
        printf ("请输入您注册的账号, 密码:\n");
        scanf ("%s %s", id, key);
        q = t;
        while(q)//判断该账号是否已经被注册
        {
            if (strcmp (q->id, id)==0)
                break;
            else q = q->next;
        }
        if (q == NULL)//账号没有注册
        {
            r = (member *)malloc(sizeof(member));
            r->next = NULL;
            p->next = r;
            strcpy (r->id, id);
            strcpy (r->key, key);
            r->sum = 1000;//会员默认的积分为1000;
            break;
        }
        else
            printf ("该账号已被注册,请重新输入账号,密码\n");
    }
    printf ("恭喜您,已经注册成功,现在可以登入了\n\n");
   
    return t;
}

int login (member *t)//登入
{
    printf ("现在开始登入");
    member *p;
    char id[20],key[20];
    int a, boo = 0;
    while (1)
    {
        printf ("请输入您的账号,密码: \n");
        scanf ("%s", id);
        if (strcmp(id, "#")==0)
            break;
        scanf ("%s", key);
        p = t;
        while (p)
        {
            if (strcmp(p->id, id)==0 &&strcmp(p->key, key)==0)
                break;
            else
                p = p->next;
        }
        if (p == NULL)
        {
            printf ("对不起,该账号和密码错误,请重新登入\n");
            printf ("推出登入请按#\n");
        }
        else if
            (strcmp(id, "0")!=0)
        {
            boo = 1;
            break;
        }
    }
    return boo;   
}
void buy()
{
    char s[20];
    int n;
    int i;
    while(1)
    {
        printf ("请输入商品的编号或者名称:\n");
        scanf ("%s", s);
        if (strcmp(s, "0")==0)
            break;
        if (s[0]>='1' && s[0]<='9')
        {
            n = atoi(s);
            for (i=0; i<1000; i++)
            {
                if (goods[i].id == n)
                    break;
            }
            if (i > 1000)
            {
                printf ("商品不存在请重新输入,推出请按0\n");
            }
            else
            {
                printf ("您已购买成功。\n");
            }
        }   
        else
        {
            for (i=0; i<1000; i++)
            {
                if (strcmp(goods[i], s)==0)
                    break;
            }
            if (i > 1000)
            {
                printf ("商品不存在,请重新输入,推出请安0\n");
            }
            else
            {
                printf ("您购买成功.\n");
            }
        }
       
    }
}

在下 小白菜, 请帮我看下代码 哪里出错了~谢谢~~~~
搜索更多相关主题的帖子: color include 超市 收银系统 
2013-02-09 03:12
心灯甚亮
Rank: 8Rank: 8
等 级:蝙蝠侠
威 望:2
帖 子:441
专家分:996
注 册:2013-1-29
得分:5 
程序代码:
# include <stdio.h> //头文件
# include <string.h> //字符串头文件
# include <stdlib.h>

typedef struct in
{
    char id[20];//会员账号
    char key[20];//会员密码
    int sum;//会员积分
    struct in *next;
}member;

struct im//商品信息 以下是私有成员
{
    int id;//商品编号
    char name[50];//商品名称
    int stoct;//商品库存
}goods[1000];

member *registe(member *t);//注册;
void buy();

int main(void)
{
    member *head = (member *)malloc(sizeof(member));
    strcpy(head->id, "0"), strcpy(head->key, "0");//超市管理员
    head->next = NULL;
    int i, a, n, boo=0;

    while(1)
    {
        printf("注册会员请按1: \n");
        printf("会员直接登入请按2:\n");
        printf("推出请按0: \n");
        scanf("%d", &a);
        if (a == 0)
            break;
        if (a == 1)
            head = registe(head);
        else if (a == 2)
            boo = login(head);
        if (boo)
            break;
    }
    if (a && boo==1)
    {
        printf ("尊贵的会员,您登入成功!\n");
        buy();
    }
    printf ("已经安全推出\n");
    return 0;
}
member *registe(member *t)//注册
{
    printf ("现在开始会员注册\n\n");
    char id[20], key[20];
    member *p, *q, *r;
    p = t;
    while(p->next) p = p->next;//寻找链表中最后一个节点
    while(1)
    {
        printf ("请输入您注册的账号, 密码:\n");
        scanf ("%s %s", id, key);
        q = t;
        while(q)//判断该账号是否已经被注册
        {
            if (strcmp (q->id, id)==0)
                break;
            else q = q->next;
        }
        if (q == NULL)//账号没有注册
        {
            r = (member *)malloc(sizeof(member));
            r->next = NULL;
            p->next = r;
            strcpy (r->id, id);
            strcpy (r->key, key);
            r->sum = 1000;//会员默认的积分为1000;
            break;
        }
        else
            printf ("该账号已被注册,请重新输入账号,密码\n");
    }
    printf ("恭喜您,已经注册成功,现在可以登入了\n\n");

    return t;
}

int login (member *t)//登入
{
    printf ("现在开始登入");
    member *p;
    char id[20],key[20];
    int a, boo = 0;
    while (1)
    {
        printf ("请输入您的账号,密码: \n");
        scanf ("%s", id);
        if (strcmp(id, "#")==0)
            break;
        scanf ("%s", key);
        p = t;
        while (p)
        {
            if (strcmp(p->id, id)==0 &&strcmp(p->key, key)==0)
                break;
            else
                p = p->next;
        }
        if (p == NULL)
        {
            printf ("对不起,该账号和密码错误,请重新登入\n");
            printf ("推出登入请按#\n");
        }
        else if
            (strcmp(id, "0")!=0)
        {
            boo = 1;
            break;
        }
    }
    return boo;
}
void buy()
{
    char s[20];
    int n;
    int i;
    while(1)
    {
        printf ("请输入商品的编号或者名称:\n");
        scanf ("%s", s);
        if (strcmp(s, "0")==0)
            break;
        if (s[0]>='1' && s[0]<='9')
        {
            n = atoi(s);
            for (i=0; i<1000; i++)
            {
                if (goods[i].id == n)
                    break;
            }
            if (i > 1000)
            {
                printf ("商品不存在请重新输入,推出请按0\n");
            }
            else
            {
                printf ("您已购买成功。\n");
            }
        }
        else
        {
            for (i=0; i<1000; i++)
            {
                if (strcmp(goods[i].name, s)==0) //编译器的提示信息看了没,看了的话应该会发现是函数参数类型不匹配
                    break;
            }
            if (i > 1000)
            {
                printf ("商品不存在,请重新输入,推出请安0\n");
            }
            else
            {
                printf ("您购买成功.\n");
            }
        }

    }
}

已编译通过。
倒着找我写的注释

[ 本帖最后由 心灯甚亮 于 2013-2-9 10:08 编辑 ]
2013-02-09 10:07
tompobing
Rank: 8Rank: 8
等 级:蝙蝠侠
帖 子:260
专家分:809
注 册:2012-12-9
得分:15 
# include <stdio.h> //头文件
 # include <string.h> //字符串头文件
 # include <stdlib.h>
 
typedef struct in
 {
     char id[20];//会员账号
     char key[20];//会员密码
     int sum;//会员积分
     struct in *next;
 }member;
 
struct im//商品信息 以下是私有成员
 {
     int id;//商品编号
     char name[50];//商品名称
     int stoct;//商品库存
 }goods[1000];
 
member *registe(member *t);//注册;
int login(member *t);     //这个函数你没有提前声明,要不你就把这个函数原型写在主函数前面  **************
 void buy();
 
int main(void)
 {
     member *head = (member *)malloc(sizeof(member));
     strcpy(head->id, "0"), strcpy(head->key, "0");//超市管理员
     head->next = NULL;
     int i, a, n, boo=0;
   
     while(1)
     {
         printf("注册会员请按1: \n");
         printf("会员直接登入请按2:\n");
         printf("推出请按0: \n");
         scanf("%d", &a);
         if (a == 0)
             break;
         if (a == 1)
             head = registe(head);
         else if (a == 2)
             boo = login(head);
         if (boo)
             break;      
    }
     if (a && boo==1)
     {
         printf ("尊贵的会员,您登入成功!\n");
         buy();
     }
     printf ("已经安全推出\n");
     return 0;
 }
 member *registe(member *t)//注册
 {
     printf ("现在开始会员注册\n\n");
     char id[20], key[20];
     member *p, *q, *r;
     p = t;
     while(p->next) p = p->next;//寻找链表中最后一个节点
     while(1)
     {
         printf ("请输入您注册的账号, 密码:\n");
         scanf ("%s %s", id, key);
         q = t;
         while(q)//判断该账号是否已经被注册
         {
             if (strcmp (q->id, id)==0)
                 break;
             else q = q->next;
         }
         if (q == NULL)//账号没有注册
         {
             r = (member *)malloc(sizeof(member));
             r->next = NULL;
             p->next = r;
             strcpy (r->id, id);
             strcpy (r->key, key);
             r->sum = 1000;//会员默认的积分为1000;
             break;
         }
         else
             printf ("该账号已被注册,请重新输入账号,密码\n");
     }
     printf ("恭喜您,已经注册成功,现在可以登入了\n\n");
   
     return t;
 }
 
int login (member *t)//登入
 {
     printf ("现在开始登入");
     member *p;
     char id[20],key[20];
     int a, boo = 0;
     while (1)
     {
         printf ("请输入您的账号,密码: \n");
         scanf ("%s", id);
         if (strcmp(id, "#")==0)
             break;
         scanf ("%s", key);
         p = t;
         while (p)
         {
             if (strcmp(p->id, id)==0 &&strcmp(p->key, key)==0)
                 break;
             else
                 p = p->next;
         }
         if (p == NULL)
         {
             printf ("对不起,该账号和密码错误,请重新登入\n");
             printf ("推出登入请按#\n");
         }
         else if
             (strcmp(id, "0")!=0)
         {
             boo = 1;
             break;
         }
     }
     return boo;   
 }
 void buy()
 {
     char s[20];
     int n;
     int i;
     while(1)
     {
         printf ("请输入商品的编号或者名称:\n");
         scanf ("%s", s);
         if (strcmp(s, "0")==0)
             break;
         if (s[0]>='1' && s[0]<='9')
         {
             n = atoi(s);
             for (i=0; i<1000; i++)
             {
                 if (goods[i].id == n)
                     break;
             }
             if (i > 1000)
             {
                 printf ("商品不存在请重新输入,推出请按0\n");
             }
             else
             {
                 printf ("您已购买成功。\n");
             }
         }   
         else
         {
             for (i=0; i<1000; i++)
             {
                 if (strcmp(goods[i].name, s)==0)   //这里你少写了.name       **************
                     break;
             }
             if (i > 1000)
             {
                 printf ("商品不存在,请重新输入,推出请安0\n");
             }
             else
             {
                 printf ("您购买成功.\n");
             }
         }
        
    }
 }




楼主的程序编译有错误,我改了下。   注释后面好多*号的是我改的地方,编译通过了。楼主自己运行看吧
2013-02-10 22:09
TonyDeng
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:304
帖 子:25859
专家分:48889
注 册:2011-6-22
得分:0 
“编译通过了”,呵呵~

授人以渔,不授人以鱼。
2013-02-10 22:13
心灯甚亮
Rank: 8Rank: 8
等 级:蝙蝠侠
威 望:2
帖 子:441
专家分:996
注 册:2013-1-29
得分:0 
回3楼:
    login函数的问题我倒没出现,编译器不同吧(我连代码都懒得看,所以没发现。。。
2013-02-10 22:15
wldnscjf
Rank: 2
等 级:论坛游民
帖 子:20
专家分:14
注 册:2013-1-27
得分:0 
回复 楼主 wldnscjf
谢谢哈~
2013-02-13 02:54
wldnscjf
Rank: 2
等 级:论坛游民
帖 子:20
专家分:14
注 册:2013-1-27
得分:0 
回复 2楼 心灯甚亮
谢谢~~~
2013-02-13 02:55
王贤晟
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2012-8-3
得分:0 
回复 2楼 心灯甚亮
请问大神,为什么我用vc++6.0编译不通过的?
2013-02-18 14:58
心灯甚亮
Rank: 8Rank: 8
等 级:蝙蝠侠
威 望:2
帖 子:441
专家分:996
注 册:2013-1-29
得分:0 
注意错误信息,它说哪里错了,就去哪里看看怎么回事,不然编译器的设计者就不用费劲添加错误、警告了
2013-02-18 15:39



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




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

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