This program is expected to do a few things: 1. Add new student using ID 2. Search for student by ID 3. Search for student by name 4. List all the students 5. Display list of students who achieved 80 marks and above
This is what I have done so far
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 200
int i;
int id;
/*Declaration of structures*/
typedef struct student{
char studID[20];
char name[50];
char address[80];
char tel_no[15];
float marks;
} stud;
int add_Name ();
int menu_Display ();
int get_Menu ();
int get_Option ();
int stud_id();
int stud_Name();
int main() {
menu_Display ();
get_Menu ();
get_Option ();
getchar();
return 0;
}
int menu_Display () {
int choice=0;
while (choice!=6) {
get_Menu ();
choice = get_Option();
}
}
int get_Menu (){
int i;
for (i=0; i<1; i++) {
printf ("\t1. Insert new student\n\n");
printf ("\t2. Search for a particular student by ID\n\n");
printf ("\t3. Search for a particular student by name\n\n");
printf ("\t4. Display a list of all students \n\n");
printf ("\t5. Display a list of students achieving 80.0 marks and above\n\n");
printf ("\t6. Exit\n\n");
}
}
int get_Option () {
int option;
printf ("Please enter your option...");
scanf ("%d", &option);
}
int menu_Option (int option) {
int i;
switch (option) {
case 1 : add_ID();
break;
case 2 : stud_id();
break;
case 3 : stud_Name();
break;
case 4 : list_students();
break;
case 5 : students_marks();
break;
case 6 : printf("Exit\n");
break;
default : printf ("Wrong input");
i=getchar();
break;
}
}
int add_ID () {
int i;
struct student stud[200];
for (i=0; i<1; i++){
strcpy(stud[i].studID,"ID00");
printf("Enter Name:\n");
scanf("%s", &(stud[i].name)) ;
printf("Enter address:\n");
scanf("%s", &(stud[i].address));
printf("Enter telephone number:\n");
scanf("%s", &(stud[i].tel_no));
printf("Enter marks:\n");
scanf("%f", &(stud[i].marks));
}
}
int stud_Name() {
int i;
int result;
char name[20];
printf("Please enter the name of the student\n");
gets(name);
for (i = 0; i < MAX; i++) {
if ((result = strcmp(stud[i].name, name)) == 0){
printf("%s \t %s \t %s \t %s \t %.2f \n", stud[i].studID, stud[i].name, stud[i].address, stud[i].tel_no, stud[i].marks);
}
if (i == MAX) {
printf ("Match not found\n");
}
i=getchar();
}
}
int stud_id() {
int i;
int result;
char ID[20];
printf("Please enter the Student ID which you are searching for\n");
gets(ID);
for (i = 0; i < MAX; i++) {
if ((result = strcmp(stud[i].studID, ID)) == 0){
printf("%s \t %s \t %s \t %s \t %.2f \n", stud[i].studID, stud[i].name, stud[i].address, stud[i].tel_no, stud[i].marks);
}
if (i == MAX) {
printf ("Match not found\n");
}
i=getchar();
}
}
int list_Students(){
printf("Student ID \t Name \t Address \t Telephone number \t Marks \n");
for (i = 0; i < MAX; i++) {
printf("%s \t %s \t %s \t %s \t %.2f \n", stud[i].studID, stud[i].name, stud[i].address, stud[i].tel_no, stud[i].marks);
}
}
I have encountered a few errors while trying to compile the program.
The error shown was "Expected expression before 'stud'" in functions stud_Name
, stud_id
and list_Students
. I have tried to modify the code but nothing works. Am I using strcmp
the right way? Thanks