Why i am unable to run this program when i try to run,this program uses structure with function .

#include <iostream>
#include <string>
using namespace std;

struct student{
int student_ID[30];
string student_name[30];
string nickname[30];
int sub;
};

struct course{
int course_code[30];
string course_name[30];
string lecturer_name[30];
};

void add_student(student detail[],int);
void display_student(student detail[],int);
void add_new_course(course info[],int);
void display_course(course info[],int);
void modify(student detail[],int);
void assign(student detail,course sub);

int i;
int j;
int size;
int size2;
int choice;
int data;
int subject;

student detail[20];
course info[20];

void main()
{

cout<<"1. Add new students"<<endl;
cout<<"2. Display student list"<<endl;
cout<<"3. Add new course"<<endl;
cout<<"4. Display Course Offered"<<endl;
cout<<"5. Modify selected student name"<<endl;
cout<<"6. Assign a student to a subject listed in the list"<<endl;
cout<<"7. End of program"<<endl;
cout<<"Please select what do wish to perform? : "<<endl;
cin>>choice;
cout<<"You entered :"<<choice<<"."<<endl;

switch (choice){
case 1:
add_student(studentdetail[i],size);
break;

case 2:
display_student(student detail[i],size);
break;

case 3:
add_new_course(course Info[j],int size2);
break;

case 4:
void display_course(course Info[j],int size2);
break;

case 5:
modify(student Detail[i],int size);
break;

case 6:
assign(student Detail,course sub);
break;

default:
printf("You chose not to do anything\n");
break;
}


void add_student(student Detail[],int size)
{
student Detail[size];

for(int i=0;i<size;i++)
{
cout<<"Enter your student ID:";
cin>> Detail[i].student_ID;

cout<<"Enter your student name:";
cin>> Detail[i].student_name;

cout<<"Enter your nickname:";
cin>> Detail[i].nickname;
}
}
void display_student(student Detail[],int size)
{
for (int i =0; i <5;i++)
{
cout<<"Enter your student ID:"<<Detail[i].student_ID<<endl;
cout<<"Enter your student name:"<<Detail[i].student_name<<endl;
cout<<"Enter your nickname:"<<Detail[i].nickname<<endl;
}
}
void add_new_course(course Info[],int size2)
{
course Info[size2];

for(int j=0;j<2;j++)
{
cout<<"Enter your course code:";
cin>> Detail[j].course_code;

cout<<"Enter your course name:";
cin>> Detail[j].course_name;

cout<<"Enter your lecturer name:";
cin>> Detail[j].lecturer_name;
}
}
void display_course(course Info[],int size2)
{
for (int j =0; j <2;j++)
{
cout<<"Enter your course code:"<<Detail[j].course_code<<endl;
cout<<"Enter your course name:"<<Detail[j].course_name<<endl;
cout<<"Enter your lecturer name:"<<Detail[j].lecturer_name<<endl;
}
}
void modify(student Detail[],int size)
{
int num, new_name;
cout<<"Enter the number of the student to modify : ";
cin>>num;
i = num-1;
cout<<"Enter new name of student : ";
cin>>data[i].new_name;
}

void assign(student Detail,course sub)
{
int num_student,num_subject ;

cout<<"Please enter number of student to assign the subject : ";
cin>>num_student;

cout<<"Choose only subject that want to assign to the student from the list. Please enter number of the subject : ";
cin>>num_subject;

i = num_student-1;
j = num_sub-1;


cout<<"Enter your student ID:"<<Detail[i].student_ID<<endl;
cout<<"Enter your student name:"<<Detail[i].student_name<<endl;
cout<<"Enter your nickname:"<<Detail[i].nickname<<endl;
cout<<endl;

cout<<"Enter your course code:"<<Detail[j].course_code<<endl;
cout<<"Enter your course name:"<<Detail[j].course_name<<endl;
cout<<"Enter your lecturer name:"<<Detail[j].lecturer_name<<endl;
cout<<endl;
}
return 0;
}
This is flat out poorly written, read a book or a couple tutorials man...

From a quick skim, you have uninitialized values in global scope and that means your function arguments are pointless. you have an array of 30 ints, names, and nicknames for every student, same for the course name and stuff, and you should make a vector of students inside the course because static arrays cant / poorly handle changing sizes. for display students it couts "enter"; name / course / code, same for display courses. add student completely rewrites all the students. same for add course. No error handling(no need when you use vectors). assign couts "enter " name / course / code, but no cin. And tons of other issues. Also make a vector of courses.

note: for vectors, if you don't know, heres how
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <vector>
//...
//inside courses
{
//...
  std::vector<student> students;
}
//in global
std::vector<course> courses;
//examples
course a_course;
a_course.course_name = "poop studies"; //and the other values...
courses.push_back(a_course);

student a_student;
a_student.student_name = "pooplover"; //and the other values...
a_student.course_code = "1337";

for(auto some_course = course.begin(); some_course != course.end(); ++some_course)
  //note the (*...), and there are other styles, like making it a pointer in the "for"
  if((*some_course).course_code == a_student.course_code) 
    (*some_course).students.push_back(a_student);
//& etc 


Hopefully I was helpful.
So how the full code would look like ?
I gave you everything you need to fix your program...
Its against the rules to completely do all the work and show all the code( so you can learn ), especially when the code is as long as yours.
Topic archived. No new replies allowed.