#include<stdio.h>
#include<iostream.h>
#include<string.h>
struct Student{
char cStuName[10];
char cPassword[8];
char cMajor[10];
Student* pNextStu;
};
struct HeadNode{
int nCount;
Student* pFirstStu;
};
void login(HeadNode* pHeader);
void zhuce(HeadNode* pHeader);
void main()
{
HeadNode *pHeader=new HeadNode;
int i=0,j=0;
pHeader->nCount=0;
pHeader->pFirstStu=NULL;
while(i<6){
printf("输入数字选择进入以下状态.");
printf("1.注册");
printf("2.登陆");
printf("3.个人信息");
printf("4.选课");
printf("5.已修课程");
printf("6.退出\n");
printf("You choice:");
scanf("%d",&i);
switch(i)
{
case 1:printf("注册");
zhuce(pHeader);
i=0;
break;
case 2:printf("登陆");
login(pHeader);
break;
case 3:printf("个人信息");
break;
case 4:printf("选课");
break;
case 5:printf("已修课程");
break;
case 6:printf("退出");
break;
default:break;
}
}
}
void zhuce(HeadNode* pHeader)
{
Student* pNewStu=new Student;
printf("输入帐号:");
cin>>pNewStu->cStuName;
if(strlen(pNewStu->cStuName)==0){
cout<<"You fail to registe."<<endl;
return;
}
printf("输入密码:");
cin>>pNewStu->cPassword;
cout<<"You are successful to registe!"<<endl;
pNewStu->pNextStu=pHeader->pFirstStu;
pHeader->pFirstStu=pNewStu;
return;
}
void login(HeadNode* pHeader)
{
char pStuName[10];
char pPassword[8];
printf("输入帐号:");
cin>>pStuName;
printf("输入密码:");
cin>>pPassword;
Student* pMove;
pMove=pHeader->pFirstStu;
while((strcmp(pMove->cStuName,pStuName)!=0||strcmp(pMove->cPassword,pPassword)!=0)&&(pMove!=NULL))
pMove=pMove->pNextStu;
if(pMove!=NULL)
cout<<"you are successful to login!"<<endl;
else
cout<<"you are illegal user!"<<endl;
}
这是一个学生选课系统的程序,只写了注册和登陆的函数.
但是,注册好了以后,在登陆的时候,不管有没有注册过,显示的结果都是"you are successful to login!".
请大家帮帮忙,看下是哪里出错了! 偶想了一个下午了.......... 谢谢先!!!
[此贴子已经被作者于2007-4-11 17:15:21编辑过]