请大家做出来给我参考下,谢谢!
#include <stdio.h> struct yonghu{ int num; char name[20]; char sex; int age; long salary; }yh[3]={{001,"liyong",'M',21,2000},{002,"xiaoli",'F',23,1700},{003,"xiaoma",'M',24,5000}}; //struct yonghu yh[3]; void again1(struct yonghu yh[3]){ int i; int n; printf("Select one yonghu by inputing his num:\n"); scanf("%d",&n); for(i=0;i<3;i++){ if(n==yh[i].num){ printf("The age of this yonghu is %d; and his salary is %d\n",yh[i].age,yh[i].salary); break; } if(i==2) printf("The yonghu you want to find is out of research!!\n"); } } int main(){ int s=0;
/* for(i=0;i<3;i++){ printf("Input the messages of the yonghu for use:\n"); printf("num:\n"); scanf("%d",&yh[i].num); printf("name:\n"); scanf("%s",&yh[i].name); //printf("\n"); printf("sex:\n"); scanf("%s",&yh[i].sex); printf("age:\n"); scanf("%d",&yh[i].age); printf("salary:\n"); scanf("%d",&yh[i].salary); printf("\n"); }*/ again1(yh); next1: printf("Select 1 to get more service or 2 to quit:"); scanf("%d",&s); if(s==1){ again1(yh); goto next1; } else if(s==2) return s; else if(s!=1&&s!=2){ printf("Your input is wrong, please chose again!\n"); goto next1; } } 没时间了,就不再注释了,你自己看看吧! 给注释掉的部分是初始化的部分,不太重要,你要是想灵活些可以启用之自己进行初始化。 有一个bug,就是我没有设置初始化用户个数的人为控制,不过很简单了!呵呵!