my list error!
-
#include<iostream> using namespace std; class list { public: int number,score; char name[10]; class list*next; }; void create(list* head) { list* p=head; while(1) { list* pp=new node; if(!pp) { cout<<"erroe"<<endl; exit(1); } cout<<"Please input the student ID:"; cin>>pp->number; if(pp->number==0) break; else { cout<<"Pleast input the studnet name"; cin>>pp->name; cout<<"Please input score:"; cin>>pp->score; p->next=pp; p=pp; } } } void show(list* head) { list* ptr=head; cout<<"\n -- STUDNET ---"<<endl; cout<<"ID\tNAME\tscore\n============================"<<endl; while(ptr!=NULL) { cout<<ptr->number<<"\t"<<ptr->name<<"\t"<<ptr->score<<endl; ptr=ptr->next; } } int main() { list* head=NULL; create(head); show(head); return 0; }
-
#include<iostream> using namespace std; class list { public: int number,score; char name[10]; class list*next; }; void create(list* head) { list* p=head; while(1) { list* pp=new node; if(!pp) { cout<<"erroe"<<endl; exit(1); } cout<<"Please input the student ID:"; cin>>pp->number; if(pp->number==0) break; else { cout<<"Pleast input the studnet name"; cin>>pp->name; cout<<"Please input score:"; cin>>pp->score; p->next=pp; p=pp; } } } void show(list* head) { list* ptr=head; cout<<"\n -- STUDNET ---"<<endl; cout<<"ID\tNAME\tscore\n============================"<<endl; while(ptr!=NULL) { cout<<ptr->number<<"\t"<<ptr->name<<"\t"<<ptr->score<<endl; ptr=ptr->next; } } int main() { list* head=NULL; create(head); show(head); return 0; }
Please read the posting guidelines[^] before posting. 1) Use the pre tag to format your code properly so that it is readable. 2) Ask a question. Dumping your code without explaining what the problem is not very useful. We can't read minds you know.
Cédric Moonen Software developer
Charting control [v3.0] OpenGL game tutorial in C++ -
#include<iostream> using namespace std; class list { public: int number,score; char name[10]; class list*next; }; void create(list* head) { list* p=head; while(1) { list* pp=new node; if(!pp) { cout<<"erroe"<<endl; exit(1); } cout<<"Please input the student ID:"; cin>>pp->number; if(pp->number==0) break; else { cout<<"Pleast input the studnet name"; cin>>pp->name; cout<<"Please input score:"; cin>>pp->score; p->next=pp; p=pp; } } } void show(list* head) { list* ptr=head; cout<<"\n -- STUDNET ---"<<endl; cout<<"ID\tNAME\tscore\n============================"<<endl; while(ptr!=NULL) { cout<<ptr->number<<"\t"<<ptr->name<<"\t"<<ptr->score<<endl; ptr=ptr->next; } } int main() { list* head=NULL; create(head); show(head); return 0; }
what error ? compile error ? runtime error ? did you try to "run" your program manually on paper (i.e. follow each step manually to see if your algo is at least valid ) ? did you try debugging it with a debugger ?
This signature was proudly tested on animals.
-
what error ? compile error ? runtime error ? did you try to "run" your program manually on paper (i.e. follow each step manually to see if your algo is at least valid ) ? did you try debugging it with a debugger ?
This signature was proudly tested on animals.
-
#include<iostream> using namespace std; class list { public: int number,score; char name[10]; class list*next; }; void create(list* head) { list* p=head; while(1) { list* pp=new node; if(!pp) { cout<<"erroe"<<endl; exit(1); } cout<<"Please input the student ID:"; cin>>pp->number; if(pp->number==0) break; else { cout<<"Pleast input the studnet name"; cin>>pp->name; cout<<"Please input score:"; cin>>pp->score; p->next=pp; p=pp; } } } void show(list* head) { list* ptr=head; cout<<"\n -- STUDNET ---"<<endl; cout<<"ID\tNAME\tscore\n============================"<<endl; while(ptr!=NULL) { cout<<ptr->number<<"\t"<<ptr->name<<"\t"<<ptr->score<<endl; ptr=ptr->next; } } int main() { list* head=NULL; create(head); show(head); return 0; }
-
#include<iostream> using namespace std; class list { public: int number,score; char name[10]; class list*next; }; void create(list* head) { list* p=head; while(1) { list* pp=new node; if(!pp) { cout<<"erroe"<<endl; exit(1); } cout<<"Please input the student ID:"; cin>>pp->number; if(pp->number==0) break; else { cout<<"Pleast input the studnet name"; cin>>pp->name; cout<<"Please input score:"; cin>>pp->score; p->next=pp; p=pp; } } } void show(list* head) { list* ptr=head; cout<<"\n -- STUDNET ---"<<endl; cout<<"ID\tNAME\tscore\n============================"<<endl; while(ptr!=NULL) { cout<<ptr->number<<"\t"<<ptr->name<<"\t"<<ptr->score<<endl; ptr=ptr->next; } } int main() { list* head=NULL; create(head); show(head); return 0; }
wbgxx wrote:
list* pp=new node;
You might start here. Once you get that corrected, you should do some serious cleanup to the
create()
function. No screen I/O should be performed in that function. Prompt the user for input elsewhere and pass that data to thecreate()
function. Also, the call tonew
inside thewhile()
loop is wrong. Is each new node added to the front of the list or the rear? If the front, nowhile()
loop is necessary. If the rear, thewhile()
loop should simply iterate each node untilNULL
is reached."One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons