mọi người cho em hỏi tại sao khi gọi hàm void XuatLopHoc thì chương trình bị lỗi không chạy được ạ
còn nhập nội dung của hàm void XuatLopHoc vào hàm main thì lại chạy được.
#include <iostream>
#include <stdlib.h>
#include <string.h>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
#define Max 10000
struct SinhVien
{
int ma;
char ten[150];
};
struct LopHoc
{
int ma;
char tenlop[150];
int siso;
SinhVien dsSV[Max];
};
void NhapSinhVien(SinhVien &sv);
void XuatSinhVien(SinhVien sv);
void NhapLopHoc(LopHoc &lh);
void XuatLopHoc(LopHoc lh);
int main(int argc, char** argv) {
LopHoc lh1;
NhapLopHoc(lh1);
cout<<"Thong tin lop hop:"<<endl;
//XuatLopHoc(lh1);
cout<<lh1.ma<<"\t"<<lh1.tenlop<<endl;
cout<<"Danh sach sinh vien:\n";
for(int i=0;i<lh1.siso;i++)
{
XuatSinhVien(lh1.dsSV[i]);
}
return 0;
}
void NhapSinhVien(SinhVien &sv)
{
cout<<"Nhap ma:";
cin>>sv.ma;
cin.ignore();
cout<<"Nhap ten:";
gets(sv.ten);
}
void XuatSinhVien(SinhVien sv)
{
cout<<sv.ma<<"\t"<<sv.ten<<endl;
}
void NhapLopHoc(LopHoc &lh)
{
cout<<"Nhap ma lop:";
cin>>lh.ma;
cin.ignore();
cout<<"Nhap ten lop:";
gets(lh.tenlop);
cout<<"Nhap si so lop:";
cin>>lh.siso;
for(int i=0;i<lh.siso;i++)
{
cout<<"Nhap sinh vien thu "<<i<<endl;
NhapSinhVien(lh.dsSV[i]);
}
}
void XuatLopHoc(LopHoc lh)
{
cout<<lh.ma<<"\t"<<lh.tenlop<<endl;
cout<<"Danh sach sinh vien:\n";
for(int i=0;i<lh.siso;i++)
{
XuatSinhVien(lh.dsSV[i]);
}
}