#include "stdio.h"
#define N 5
struct recipe
{
char *dishes;
int k;
}rec[N]={"abcd",20,"befd",25,"qwer",33,"poiu",61,"srst",79};
void main()
{
int i,sum=0;
char ch[20];
for( i=0;i<N;i++ )
{
printf( "菜名:%s\n菜价:%d\n",rec[i].dishes,rec[i].k );
}
printf( "input dishes:\n input ok over\n" );
lopp:
scanf( "%s",ch );
for( i=0;i<N;i++ )
{
if(strcmp(ch,rec[i].dishes)==0)
{
sum=sum+rec[i].k;
}
}
printf( "%d\n",sum );
goto lopp;
}
刚刚学到结构体拿来做个练习题
我也不知道可不可以