Почему я получаю ошибку сегментации в следующей программе C++?
#include <iostream> #include <string> #include <stdlib.h> using namespace std; struct person { string f_name; string l_name; int st_no; string email; }; struct phone { string int_code; string cnt_code; string reg_code; string h_code; }; int main() { person p[2]; phone n[2]; int a,i=0,x; char ch,q; do { cout<<"*********************************************************"<<endl; cout<<"="" student="" management="" application:"<<endl; ="" cout<<"*********************************************************"<<endl; ="" cout<<"1.create="" and="" add="" a="" student."<<endl; ="" cout<<"2.search="" for="" by="" number."<<endl; ="" cout<<"3.display="" the="" students="" list."<<endl; ="" cout<<"4.exit="" application."<<endl; ="" cout<<"enter="" your="" choice:="" "<<endl; ="" cin="">>a; { if(a==1) { for(i=0;i<=2;++i) { cout<<"enter first name:"<<endl; cin="">>p[i].f_name; cout<<"enter last name:"<<endl; cin="">>p[i].l_name; cout<<"enter student no. (from 1 to 10):"<<endl; cin="">>p[i].st_no; cout<<"enter student email ID:"<<endl; cin="">>p[i].email; cout<<"please enter phone details:\n\n\n"; cout<<"enter international code:"<<endl; cin="">>n[i].int_code; cout<<"enter country code:"<<endl; cin="">>n[i].cnt_code; cout<<"enter regional code:"<<endl; cin="">>n[i].reg_code; cout<<"enter home code:"<<endl; cin="">>n[i].h_code; } } else if(a==2) { do { cout<<"enter the student number:"<<endl; cin="">>x; for(i=0;i<=2;i++) { if(x==p[i].st_no) { cout<<"student name ="<<p[i].f_name<<" "<<p[i].l_name<<endl; ="" } ="" cout<<"want="" to="" search="" for="" another="" student?="" y="" n"<<endl; ="" cin="">>q; }while(q=='y'); } else if(a==3) { cout<<"student list:"<<endl; for(int="" i="0;" i<="2;" i++) ="" { ="" cout<<p[i].f_name<<"="" "<<p[i].l_name<<endl; ="" } ="" else ="" if(a="=4) " {="" break; ="" cout<<"sorry!="" something="" is="" wrong...="" :("<<endl; ="" } ="" cout<<"do="" you="" want="" to="" anything="" else?="" y="" n"<<endl; ="" cin="">>ch; } while(ch=='y'); return 0; }
Что я уже пробовал:
я понятия не имею, что делать!