读书人

急求高手处理的程序麻烦你们帮下手看

发布时间: 2012-03-13 11:21:11 作者: rapoo

急求高手处理的程序,麻烦你们帮下手看下哪里错
#include<stdio.h>
#include<malloc.h>
#include<string.h>
#include<stdlib.h>
#define LEN sizeof(struct point)
struct point
{
int skjbh ;

int spbh ;

int xssl ;

double money ;
struct point *next ;
} ;


int n,a ;


struct point * creat (void)

{
struct point *head ;

struct point *p1 ,* p2;

n = 0 ;

head = NULL ;

while ( 4)

{
n=n+1 ;

p1=(struct point *)malloc(LEN) ;

printf("enter the four :\n") ;

scanf("%d",&p1 -> skjbh);

if(p1 -> skjbh==0)break;

scanf("%d%d%f",&p1->spbh ,&p1->xssl,&p1->money ) ;

if ((p1 ->money ) ==0 ) break ;
if(n==1) head = p1 ;

else

p2->next = p1 ;

p2=p1 ;

}

p2->next =NULL ;

return (head) ;
}

/*void save(struct point * head)
{struct point * p3;
FILE * fp;
p3=head;
if((fp=fopen("supermarket.txt","w+"))==NULL)
{printf("cannot open file\n");
exit(0);
}
fputs("收款机编号 商品编号 销售数量 销售金额\n",fp);

for(a=1;a<n+1;a++)
{fprintf(fp,"%4d%4d%4d%4.1f\n",p3->skjbh ,p3->spbh ,p3->xssl,p3->money) ;

p3=p3->next;
}
fclose(fp);
}*/

double GetTotleMoney(int skjbh,struct point *head,int xssl)/*统计每台收款机的销售总额;*/
{double nTotle = 0;
int i;
struct point *head;
struct point *pTemp;
if(head== NULL || xssl < 1)
{
return 0;
}
for(i=0;i<xssl;i++)
{
pTemp =head;
if(pTemp != NULL && pTemp->skjbh == skjbh)
nTotle+=(pTemp->xssl)*(pTemp->money);}
return nTotle;
}

void main()

{
struct point * head;
head=creat() ;
save(head);
//GetTotleMoney(head);
}



[解决办法]

C/C++ code
#define  LEN sizeof(struct  point) struct  point {     int  skjbh ;         int  spbh ;         int  xssl ;         double  money ;     struct point *next ; } ; int  n,a ; struct  point * creat (void) {     struct  point *head ;         struct  point *p1 ,* p2;         n = 0 ;         head = NULL ;         while ( 4)             {         n=n+1 ;                 p1=(struct point *)malloc(LEN) ;                 printf("enter the four :\n") ;                 scanf("%d",&p1 -> skjbh);                 if(p1 -> skjbh==0)break;                 scanf("%d%d%f",&p1->spbh ,&p1->xssl,&p1->money ) ;                 if ((p1 ->money ) ==0 )  break ;         if(n==1) head = p1 ;                 else                         p2->next = p1 ;                 p2=p1 ;             }         p2->next =NULL ;         return (head) ; } /*void save(struct point * head) {struct point * p3; FILE * fp; p3=head; if((fp=fopen("supermarket.txt","w+"))==NULL) {printf("cannot open file\n"); exit(0); } fputs("收款机编号    商品编号    销售数量    销售金额\n",fp);   for(a=1;a <n+1;a++)   {fprintf(fp,"%4d%4d%4d%4.1f\n",p3->skjbh ,p3->spbh ,p3->xssl,p3->money) ;       p3=p3->next;      }     fclose(fp); }*/ double GetTotleMoney(int skjbh,struct point *head,int xssl)/*统计每台收款机的销售总额;*/    {    double nTotle = 0;     int i;     //struct point *head;               //这里重定义了    struct point *pTemp;     if(head== NULL || xssl < 1)        {              return 0;        }        for(i=0;i <xssl;i++)      {                    pTemp =head;                    if(pTemp != NULL && pTemp->skjbh == skjbh)                            nTotle+=(pTemp->xssl)*(pTemp->money);}            return nTotle; } void  main() {     struct point * head;     head=creat() ;     save(head);             //GetTotleMoney(head); } 


[解决办法]

C/C++ code
double GetTotleMoney(int skjbh,struct point *head,int xssl)/*统计每台收款机的销售总额;*/    {double nTotle = 0; int i; struct point *head; //重定义了head变量,跟GetTotleMoney(int skjbh,struct point *head,int xssl)中的head重名了,这里要换个名字struct point *pTemp; if(head== NULL || xssl < 1)    {      return 0;    }    for(i=0;i <xssl;i++)  {            pTemp =head;            if(pTemp != NULL && pTemp->skjbh == skjbh)                nTotle+=(pTemp->xssl)*(pTemp->money);}        return nTotle; }
[解决办法]
VC10编译通过

C/C++ code
#include  <stdio.h>  
#include <malloc.h>
#include <string.h>
#include <stdlib.h>

#define LEN sizeof(struct point)
struct point
{
int skjbh ;

int spbh ;

int xssl ;

double money ;
struct point *next ;
} ;


int n,a ;


struct point * creat (void)

{
struct point *head ;

struct point *p1 ,* p2;

n = 0 ;

head = NULL ;

while ( 4)

{
n=n+1 ;

p1=(struct point *)malloc(LEN) ;

printf("enter the four :\n") ;

scanf("%d",&p1 -> skjbh);

if(p1 -> skjbh==0)break;

scanf("%d%d%f",&p1->spbh ,&p1->xssl,&p1->money ) ;

if ((p1 ->money ) ==0 ) break ;
if(n==1) head = p1 ;

else

p2->next = p1 ;

p2=p1 ;

}

p2->next =NULL ;

return (head) ;
}

/*void save(struct point * head)
{struct point * p3;
FILE * fp;
p3=head;
if((fp=fopen("supermarket.txt","w+"))==NULL)
{printf("cannot open file\n");
exit(0);
}
fputs("收款机编号 商品编号 销售数量 销售金额\n",fp);

for(a=1;a <n+1;a++)
{fprintf(fp,"%4d%4d%4d%4.1f\n",p3->skjbh ,p3->spbh ,p3->xssl,p3->money) ;

p3=p3->next;
}
fclose(fp);
}*/

double GetTotleMoney(int skjbh,struct point *head,int xssl)/*统计每台收款机的销售总额;*/
{
double nTotle = 0;
int i;
//struct point *head; //这里重定义了
struct point *pTemp;
if(head== NULL || xssl < 1)
{
return 0;
}
for(i=0;i <xssl;i++)
{
pTemp =head;
if(pTemp != NULL && pTemp->skjbh == skjbh)
nTotle+=(pTemp->xssl)*(pTemp->money);}
return nTotle;
}

void main()

{
struct point * head;
head=creat() ;
// save(head);


//GetTotleMoney(head);
}


[解决办法]
#include <stdio.h>
#include <malloc.h> //不能打开
#include <string.h>
#include <stdlib.h>

。。。。。
double GetTotleMoney(int skjbh,struct point *head,int xssl)/*统计每台收款机的销售总额;*/
{
struct point *head; //这里重定义了
struct point *pTemp;
if(head== NULL || xssl < 1)
{
return 0;
}
。。。。
}

读书人网 >C语言

热点推荐