| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 425 人关注过本帖
标题:哪位大侠帮忙看下为什么我的程序中数量保存不住,当有两个一样的名字时,数 ...
只看楼主 加入收藏
q875312468
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2012-9-17
结帖率:100%
收藏
已结贴  问题点数:10 回复次数:1 
哪位大侠帮忙看下为什么我的程序中数量保存不住,当有两个一样的名字时,数量为什么不累加
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#define MAX 1000  //最大值定义为100
struct DATE
{
int year;
int month;
int day;
};
struct member
{
char name[40];
int num;
int price;
struct DATE intime;
}in1[MAX],in2[MAX],*p,*q;
struct sum
{
char name[40];
int numb;
int price;
}zongji[MAX],*m;
void Initin()   //结构体初始化
{
    for(int i=0;i<MAX;i++)
        {
            in1[i].num=0;
            in1[i].price=0;
            in2[i].num=0;
            in2[i].price=0;
        }
}
void tianjia1(struct member *p)
{
    printf("请输入要添加物品的名称:");
    scanf("%s", p->name);
    printf("\n");
    printf("\n");
    printf("请输入要添加物品的价格:");
    scanf("%d",&p->price);
    printf("\n");
    printf("\n");
    printf("请输入要添加物品的数量: ");
    scanf("%d",&p->num);
    printf("\n");
    printf("\n");
    printf("请输入添加物品的时间(xx-xx-xx): ");
    scanf("%d-%d-%d",&p->intime.year,&p->intime.month,&p->intime.day);
}
void tianjia2(struct member *q)
{
    printf("请输入要添加物品的名称:");
    scanf("%s", q->name);
    printf("\n");
    printf("\n");
    printf("请输入要添加物品的价格:");
    scanf("%d",&q->price);
    printf("\n");
    printf("\n");
    printf("请输入要添加物品的数量: ");
    scanf("%d",&q->num);
    printf("\n");
    printf("\n");
    printf("请输入添加物品的时间(xx-xx-xx): ");
    scanf("%d-%d-%d",&q->intime.year,&q->intime.month,&q->intime.day);
}

void Menu()  //菜单
{
 printf("┏—————————————————M  E  N  U————————————————┓\n");
 printf("│                                                                            │\n");
 printf("│  1. 衣方面花费                                                             │\n");
 printf("│  2. 食方面花费                                                             │\n");
 printf("│  3. 行方面花费                                                             │\n");
 printf("│  4. 通讯类花费                                                             │\n");
 printf("│  5. 其他类花费                                                             │\n");
 printf("│  6. 衣方面合计                                                             │\n");
 printf("│  7. 食方面合计                                                             │\n");
 printf("│  8. 行方面合计                                                             │\n");
 printf("│  9. 通讯方面合计                                                           │\n");
 printf("│  10. 其他类合计                                                            │\n");
 printf("┗—————————————请 选 择 你 需 要 的 操 作————————————┛\n");
}
void cMenu()
{
 printf("┏—————————————————————————————————┓\n");
 printf("│                                                                  │\n");
 printf("│                 1.小胖子               2小瘦子                   │\n");
 printf("│                                                                  │\n");
 printf("┗——————————请 选 择 你 需 要 的 操 作——————————┛\n");
}
void dMenu()
{
 printf("┏—————————————————————————————————┓\n");
 printf("│                                                                  │\n");
 printf("│                      1.水               2电                      │\n");
 printf("│                                                                  │\n");
 printf("┗——————————请 选 择 你 需 要 的 操 作——————————┛\n");
}
void xianshi1(struct member *p)
{
    printf("┏━━━━━━━┳━━━━━━━┳━━━━━━━━┳\n");
    printf("┃     名字          数量           价格      ┃\n");
    printf("┣━━━━━━━╋━━━━━━━╋━━━━━━━━┫\n");
    printf("┃%14s┃%14d┃%16d┃\n",p->name,p->num,p->price);
    printf("┗━━━━━━━┻━━━━━━━┻━━━━━━━━┛\n");
    printf("%d-%d-%d",p->intime.year,p->intime.month,p->intime.day);
    printf("\n");
    printf("\n");
    p++;
}
void xianshi2(struct member *q)
{
    printf("┏━━━━━━━┳━━━━━━━┳━━━━━━━━┳\n");
    printf("┃     名字          数量           价格      ┃\n");
    printf("┣━━━━━━━╋━━━━━━━╋━━━━━━━━┫\n");
    printf("┃%14s┃%14d┃%16d┃\n",q->name,q->num,q->price);
    printf("┗━━━━━━━┻━━━━━━━┻━━━━━━━━┛\n");
    printf("%d-%d-%d",q->intime.year,q->intime.month,q->intime.day);
    printf("\n");
    printf("\n");
    q++;
}

void main()
{
     Initin();
     int totle=0;
     p=in1;
     q=in2;
     printf("-----------------------欢 迎 进 入 超 级 管 家 系 统!---------------------------\n\n");
     int choice=5;
     int cchoice;
     while(choice!=0)
     {
         Menu();//显示菜单
         scanf("%d",&choice);
         switch(choice)
         {
         case 1:
         cMenu();
         scanf("%d",&cchoice);
                 switch(cchoice)
                     {
                         case 1:
                         tianjia1(p);
                         xianshi1(p);
                         break;
                         case 2:
                         tianjia2(q);
                         xianshi2(q);
                         break;
                     }
         break;
         case 6:
         cMenu();
         scanf("%d",&cchoice);
         switch(cchoice)
             {
                 case 1:
                     int j;
                     m=zongji;
                     printf("请输入要总计的产品名称:");
                     scanf("%s",m->name);
                    for(j=0;j<=MAX;j++)
                    {
                        if(strcmp(m->name,p->name)==0)//如果名一样
                            {
                                m->numb=m->numb+p->num;
                                p--;
                                m++;
                            }
                    }
                    printf("%d",m->numb);
             }
         }
    }
}
搜索更多相关主题的帖子: member 结构体 include 
2012-09-17 00:52
青春无限
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:江苏
等 级:贵宾
威 望:24
帖 子:3452
专家分:19340
注 册:2012-3-31
收藏
得分:10 
学习

学 会看代码…学习写程序…学会搞开发…我的目标!呵呵是不是说大话啊!!一切皆可能
2012-09-17 09:04
快速回复:哪位大侠帮忙看下为什么我的程序中数量保存不住,当有两个一样的名字时 ...
数据加载中...
 
   



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

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