This is the program i'm trying to develop. It's not an assignment or anything. I'm just a newbie trying out new stuff. But I'm getting frustrated with this.

#include <iostream>
using namespace std;

//========== struct ==========

struct nodeType
{ string song;
  int rating;
  nodeType *link;
}; 

//------------------------------------------------------------------------------
//========== function ==========

nodeType* song_info ()
{
  nodeType *first, *newNode, *last, *p;
  string Song;
  int Rating;
  
  //========== input ==========
  cout << "To end the program enter -999" << endl;
  
  cout << "Enter song : ";
  getline (cin, Song);
  cout << endl;
  
  cout << "Enter rating : ";
  cin >> Rating;
  cout << endl;
  
 
  first = NULL;
  
  while (Song != "-999")
  { 
    newNode = new nodeType;
    newNode -> song = Song;    

    newNode -> rating = Rating;
    
    
    newNode -> link = NULL;
    
    if (first == NULL)
    { 
      first = newNode;
      last = newNode;
    }

    else
    
    {
      last -> link = newNode;
      last = newNode;
    }
    
  cout << "Enter song : ";
  getline (cin, Song);
  cout << endl;
  
  cout << "Enter rating : ";
  cin >> Rating;
  cout << endl;
  } 
  
  system ("cls");
  cout << endl;
  cout << "=========================================================="<< endl;

  //========== display ==========

  cout << endl;
  last = first;
  while (last != NULL)
  { 
   cout << "Song       : " << last -> song << endl << endl 
        << "Rating     : " << last -> rating << endl << endl;
   last = last -> link;
   cout << endl << endl;
   cout << "=========================================================="<< endl;
   cout << endl; 
  }
}

//------------------------------------------------------------------------------
//========== main ==========
int main ()
{
  song_info();
  
  system ("pause");
  return 0;
}

The first input was alright, the problem is the second round of the loop. Please help me with this.

You have one massive function to do everything.

Break your list steps into
- initialise list
- append to list
- print list
- destroy list

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.