hi i decided to make my linked list program accept getline characters
so i use getline( cin,s) which use string s declared in string
why is no error but the part of reading getline(cin,s) doesn't get input??
here's my coding
Code:#include<iostream> #include<cstring> #include<string.h> using namespace std; struct node { string course,coursename,name; int matric; float chour; node *next; } yours; node *start_node=NULL; node *current; int option=0; void add_node() { node *temp,*temp2; temp=new node; cout << "enter a course code : " ; getline (cin,temp->coursename); cout << "enter a subject : " ; cin >> temp->course; cout << "enter the credit hour : " ; cin >> temp->chour; cout << endl; temp->next=NULL; if(start_node==NULL) { start_node=temp; current=start_node; } else { temp2=start_node; while(temp2->next!=NULL) { temp2=temp2->next; } temp2->next=temp; } } void display_node() { node *temp; temp=start_node; if(temp==NULL) { cout << "the list is empty" << endl; } else { /*void display() //display function { cout<<endl; schedule *temp; temp=ptr_head; int c=1; if(temp==NULL) //check whether the stack is empty { cout<<"EMPTY"<<endl; } else //print if stack not empty { cout<<"- This is the Course Registration Period"<<endl; cout<<"- Range of Matric No - Time Period -"<<endl; cout<<"------------------------------------------------------------"<<endl; while(temp!=NULL) { cout<<" "<<c<<" "<<temp->matric<<" "<<temp->matric2<<" "<<temp->time<<" "<<temp->time2<<endl; temp=temp->next; c++; } cout<<"------------------------------------------------------------"<<endl; } cout<<endl; }*/ cout<<"- This is your course registration slip for this semester"<<endl; cout<<"- Cours Name - Course code - credit hours"<<endl; cout<<"------------------------------------------------------------"<<endl; while(temp!=NULL) { cout<<" "<<temp->course<<" "<<temp->coursename<<" "<<temp->chour<<" "<<endl; temp=temp->next; cout << endl; } cout<<"------------------------------------------------------------"<<endl; cout << "the list is finished" << endl; } } void del_start_node() { node *temp; temp=start_node; start_node=start_node->next; if(temp==NULL) { cout << "can't delete coz list is empty" << endl; } else{ cout << "first node is deleted " << endl; delete temp; } } void del_end_node() { node *temp,*temp2; if(start_node==NULL) { cout << "can't delete node coz list is empty" << endl; } else { temp=start_node; if(temp->next!=NULL) { delete temp; start_node=NULL; } else { temp2=temp; temp=temp->next; } delete temp; temp2->next=NULL; } } int main() { int matric; string name; cout << "enter a your name : " ; cin >>name; cout<< endl; cout << "enter a matric number : " ; cin >>matric; cout << endl; int option; do { cout << "please choose ..." << endl; cout << "0 to exit " << endl; cout << "1 to add subject " << endl; cout << "2 to delete first subject " << endl; cout << "3 to delete last subject " << endl; cout << "4 to display the list of your registered subjects " << endl; cin >> option; switch(option) { case 1 : add_node(); break; case 2 : del_start_node(); break; case 3 : del_end_node(); break; case 4 : /*printf("\n------------------\n"); printf("ID number: %s\n", studno_1.id_num); printf("Name : %s\n", studno_1.name); printf("Gender : %c\n", studno_1.gender); printf("Age : %d\n", studno_1.age); printf("------------------\n");*/ cout<<"\n-----------------------------"<<endl; cout << "NAME :" <<name <<"\t"<<endl; cout << "MATRIC NUMBER :"<<matric<<"\t"<<endl; cout<<"-----------------------------\n"<<endl; display_node(); break; } }while(option!=0); system("pause"); return 0; }



LinkBack URL
About LinkBacks


