Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. my list error!

my list error!

Scheduled Pinned Locked Moved C / C++ / MFC
help
6 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    wbgxx
    wrote on last edited by
    #1

    #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; }

    C M L D 4 Replies Last reply
    0
    • W wbgxx

      #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; }

      C Offline
      C Offline
      Cedric Moonen
      wrote on last edited by
      #2

      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++

      1 Reply Last reply
      0
      • W wbgxx

        #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; }

        M Offline
        M Offline
        Maximilien
        wrote on last edited by
        #3

        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.

        L 1 Reply Last reply
        0
        • M Maximilien

          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.

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          I suspect it was what is commonly described as 'cockpit error'. ;P :-D

          L u n a t i c F r i n g e

          1 Reply Last reply
          0
          • W wbgxx

            #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; }

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            Please read the gudelines[^] and reformat your post so the code is within <pre></pre> tags and correctly indented. That way we can read it. Secondly try to add a question, as this entry is meaningless.

            MVP 2010 - are they mad?

            1 Reply Last reply
            0
            • W wbgxx

              #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; }

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #6

              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 the create() function. Also, the call to new inside the while() loop is wrong. Is each new node added to the front of the list or the rear? If the front, no while() loop is necessary. If the rear, the while() loop should simply iterate each node until NULL 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

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups