-
Student records program
Okay so I have a project, im almooost done, i just lack a certain function.
Code:
void add_record(record x, FILE *fp)
{
char ans;
int tempid;
do
{
system("cls");
INPUT:
printf("Student ID: "); scanf("%d", &x.idno);
fflush(stdin);
printf("First Name: "); gets(x.Fname);
printf("Last Name; "); gets(x.Lname);
strupr(x.Lname);
printf("Course: "); gets(x.course);
printf("Age: "); scanf("%d", &x.age);
fflush(stdin);
printf("Tuition: "); scanf("%f", &x.tuition);
system("cls");
printf("Enter another record? Y/N");
ans=toupper(getch());
system("cls");
fwrite(&x,sizeof(x),1,fp);
}while(ans=='Y');
fclose(fp);
}
If the user inputs a Student Number which already exists, i want my program to ask the user again for another number and display sumthing like "Student Number already exists. Try again"
I've tried working it out myself, but every time I input a Student Number , the program displays that it already exists, even though its not.
What do you suggest I do?? Pleassee i need help, the project is due tomorrow :(
-
Well, you might start with the code that shows the problem you're having...
There is nothing in your provided sample that even approaches testing for existing codes or printing error messages about them.
-
Is that a goto label I see there?
-
Hope that you'll be storing student Number somewhere in your program.
After you get input student_Number, call a function that will;
return 0 in case, if it finds the same number, else return 1.
After this, you can further procede with your program.