Stupid request i know :S but i wrote this program so long ago and my C++ knowledge is so bad i need help remembering how it works :( ive completely forgot how linked lists work ive been working with javascript + java and amoung all my uni assignments my brain is fried so could someone please help comment as much of my code as they can to get me started please


thanks for anyhelp :)

#include <iostream.h>
 
typedef struct characters {
        int id;
        int health;
        int inteligence;
        struct characters *next;
        struct characters *prev;
} characters;

characters *newcharacters(characters *characterspointer, int id, int health, int inteligenceint);

void print(characters *);
void printreverse(characters *);

typedef struct spell {
        int sid;
        int sdamage;
        struct spell *next;
        struct spell *prev;
} spell;

spell *newspell(spell *spellpointer, int id, int damage);

void prints(spell *);
void printreverses(spell *);


main()
{
   int quit;
   characters *characterspointer;
   spell *spellpointer;
   spellpointer=NULL;
   characterspointer = NULL;
   int sid;
   int sdamage;
   int id;
   int inteligence;
   int health;
   
   cout<<endl<<endl<<"Make Your Choice"<<endl; 
   cout<<"1 = New Character"<<endl;
   cout<<"2 = Fight?"<<endl;
   cout<<"2 = Scroll Character List"<<endl;
   cout<<"7 = List Characters"<<endl;
   cout<<"8 = List Spells"<<endl;
   cout<<"9 = Menu"<<endl;
   cout<<"**to quit press 0 at any time**"<<endl;

  cin>>quit;  
   while (quit!=0)
   {        
         if(quit==1)
         {
                    cout<<"Enter char ID.";
                    cin>>id;
      
                    health=10;
                    inteligence=1;
         if (id!=0){
                    characterspointer = newcharacters(characterspointer, id, health, inteligence);
                    }
                     print(characterspointer);
                     cout<<endl;
                     printreverse(characterspointer);
                     cout<<"add new char ? 1 for yes, 9 for main menu";
                     cin>>quit;
         }
         
         
         if(quit==2)
         {
         int monster=30;
         int fite;
         cout<<"Theres a monster, kill ?"<<endl;
         cout<<"2 to FITE !!!"<<endl;
         cin>>quit;
         
             while(quit==2){
                            cout<<"POWPOW"<<endl;
                            cout<<"Press 2 to fight, 9 to retreat."<<endl;
                            characterspointer->health=health;
                            health=health-3;
                            monster = monster - 10;
                            cout<<characterspointer->health<<endl;
                            cout<<monster<<endl;
                            cout<<"fight again (press 2 for yes, 9 for menu."<<endl;
                            
                            if (health <=0){
          
                                     cout<<"you died, gutted."<<endl<<endl;
                                     cin>>quit;
                                     }
                                     if (monster<=0){
                                    
                                    cout<<"Congrats, You win"<<endl;
                                    cout<<"A new spell will be added"<<endl;
         
                                    sdamage=1;
                                    sid=1;
                    
         if (quit!=0){
                     spellpointer = newspell(spellpointer, sid, sdamage);
                    }
                     prints(spellpointer);
                     cout<<endl;
                     printreverses(spellpointer);
                     quit=9;
               }
               
          if (health>0){
                    cin>>quit;
                    }
               }
           }
          if(quit==3)
         {
                   if (characterspointer->next == NULL)
                   cout << "You are at the end of the list." << endl;
                   else
         
                   characterspointer = characterspointer->next;
                   cout<<characterspointer->id;

                   cin>>quit;
         }
         
          if(quit==7)
         {           
                     cout<<"List of characters"<<endl<<endl;
                     print(characterspointer);
                     cout<<endl;
                     printreverse(characterspointer);
                     cin>>quit;
                    }
                    
         if(quit==8)
         {           
                     cout<<"List of spells"<<endl<<endl;
                     prints(spellpointer);
                     cout<<endl;
                     printreverses(spellpointer);
                     cin>>quit;
                    }
         
          if(quit==9)
         {           
                     cout<<endl<<endl<<"Make Your Choice"<<endl; 
                     cout<<"1 = New Character"<<endl;
                     cout<<"2 = Fight?"<<endl;
                     cout<<"2 = Scroll Character List"<<endl;
                     cout<<"7 = List Characters"<<endl;
                     cout<<"8 = List Spells"<<endl;
                     cout<<"9 = Menu"<<endl;
                     cout<<"**to quit press 0 at any time**"<<endl;
                     cin>>quit;
         }
      }       
  
}

characters * newcharacters(characters *characterspointer, int id, int health, int inteligence)
{
        characters *chas;
   chas = characterspointer;
   if(characterspointer!=NULL)
   {
      characterspointer->next = newcharacters(characterspointer->next, id, health, inteligence);
        return chas;
   }
   else
   {
      characters * characterspointer= new characters;
      characterspointer->next = NULL;
      characterspointer->prev = NULL;
      characterspointer->id = id;
      characterspointer->health=health;
      characterspointer->inteligence=inteligence;
      return characterspointer;
   }
}

void print(characters *characterspointer)
{
        if (characterspointer != NULL)
   {
      cout<<characterspointer->id<<" = Player ID."<<endl;
      cout<<characterspointer->health<<" = Health."<<endl;
      cout<<characterspointer->inteligence<<" = Inteligence."<<endl;
      print(characterspointer->next);
   }
}
void printreverse(characters *characterspointer)
{
        if (characterspointer != NULL)
   {
      printreverse(characterspointer->next);
      cout<<characterspointer->id<<" = Player ID."<<endl;
      cout<<characterspointer->health<<" = Health."<<endl;
      cout<<characterspointer->inteligence<<" = Inteligence."<<endl;
   
}}
   
spell * newspell(spell *spellpointer, int sid, int sdamage)
{
spell *temp;
   temp = spellpointer;
   if(spellpointer!=NULL)
   {
      spellpointer->next = newspell(spellpointer->next, sid, sdamage);
        return temp;
   }
   else
   {
      spell * spellpointer= new spell;
      spellpointer->next = NULL;
      spellpointer->prev = NULL;
      spellpointer->sid = sid;
      spellpointer->sdamage=sdamage;
      return spellpointer;
   }
}

void prints(spell *spellpointer)
{
        if (spellpointer != NULL)
   {
      cout<<spellpointer->sid<<" = spell ID."<<endl;
      cout<<spellpointer->sdamage<<" = Spell Damage."<<endl;
      prints(spellpointer->next);
   }
}
void printreverses(spell *spellpointer)
{
        if (spellpointer != NULL)
   {
      printreverses(spellpointer->next);
      cout<<spellpointer->sid<<" = Spell ID."<<endl;
      cout<<spellpointer->sdamage<<" = Spell Damage."<<endl;
   
}   }

Why don't you read through it yourself? It will do you more good than us wading through 240+ lines reverse-engineering something.

I'll get you started, I see 7 functions (including an improperly-declared main()) and 2 custom data types.

If there's something you can't figure out, ask a specifically-directed question and you'll be more likely to get better help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.