I'm having trouble inputting the student ID. The way its supposed to work is that the ID is supposed to correlate with each index, meaning if each index is a student, then the ID is equivalent to the order in which each student is inputted. So index 0 is ID 0 and student index 85 is ID 85. I'm also wondering how would it be correct to print the info according to choice 4.
Here is a sample of how things are supposed to work as given by my teacher:
Press 1 for author info
Press 2 to login
2
Enter user name
Kenny
Enter password
Lofton
Login Successful
Press 0 to exit
Press 1 for author info
Press 2 to Enter new student
Press 3 to enter grade for existing student
Press 4 to print student records
Press 5 to save student records
Press 6 to load student records
Press 7 to logout
2
Enter student first name
tim
Enter student last name
kon
Press 0 to exit
Press 1 for author info
Press 2 to Enter new student
Press 3 to enter grade for existing student
Press 4 to print student records
Press 5 to save student records
Press 6 to load student records
Press 7 to logout
3
Enter student ID
0
Enter the numeric value of the grade point for this class
t
5.4
Press 0 to exit
Press 1 for author info
Press 2 to Enter new student
Press 3 to enter grade for existing student
Press 4 to print student records
Press 5 to save student records
Press 6 to load student records
Press 7 to logout
3
Enter student ID
0
Enter the numeric value of the grade point for this class
t
4.2
Press 0 to exit
Press 1 for author info
Press 2 to Enter new student
Press 3 to enter grade for existing student
Press 4 to print student records
Press 5 to save student records
Press 6 to load student records
Press 7 to logout
4
First Name: tim Last Name: kon: GPA: 4.800000
5.400000
4.200000
Press 0 to exit
Press 1 for author info
Press 2 to Enter new student
Press 3 to enter grade for existing student
Press 4 to print student records
Press 5 to save student records
Press 6 to load student records
Press 7 to logout
Here is my code so far:
Code:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
typedef struct student
{
char fname[100], lname[100];
double grades[100];
int ID;
}student;
int main()
{
student arr[1000];
int j = 0;
int i = 0;
int a = 0;
char username[100];
char password[100];
char fusername[100], fpassword[100];
while (1)
{
printf("Press 1 for author info\nPress 2 to Log in\n");
scanf("%d", &a);
if (a == 1)
{
printf("Timofey Kononets\n2651763\n");
}
if (a == 2)
{
FILE *file = fopen("passwords1.txt", "r");
printf("Enter a user name\n");
scanf("%s", username);
printf("Enter password\n");
scanf("%s", password);
while (fscanf(file, "%s%s", fusername, fpassword) != EOF)
{
if (strcmp(username, fusername) == 0)
{
if (strcmp(password, fpassword) == 0)
{
printf("Login successful\n");
}
else
{
printf("Login unsuccessful\n");
}
}
}
fclose(file);
}
while (2)
{
printf("Press 1 for author info\nPress 2 to enter new student\nPress 3 to enter grade for existing student\nPress 4 to print student records\nPress 5 to save student records\nPress 6 to load student records\nPress 7 to logout\n");
scanf("%d", &a);
if (a == 1)
{
printf("Timofey Kononets\n2651763\n");
}
else if (a == 2)
{
printf("Enter student first name\n");
scanf("%s", arr[i].fname);
printf("Enter student last name\n");
scanf("%s", arr[i].lname);
i++;
}
else if (a == 3)
{
printf("Enter student ID\n");
scanf("%d", arr[j].ID);
printf("Enter a numeric value for the gradepoint in this class\n");
scanf("%lf", arr[j].grades);
}
else if (a == 4)
{
for (int k = 0; k < i; k++)
{
printf("First name: %s Last Name: %s GPA: %lf\n", arr[k].fname, arr[k].lname, arr[k].grades);
}
}
}
if (a == 0)
{
exit(0);
}
}
system("pause");
return (0);
}