help!!!

how do I make a linked list array perform how ever many while loops that they want? got everything else but do not know what to do to set the while loop to end when the number of input the user wants is done?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71

#include <iomanip>
#include <iostream>
#include <string>
using namespace std;

struct Student
{
  string name;
  int id;
  float gpa;
  Student* next; // the link
};


int main()
{
  // Prompt user to input how many records they would like to view and have sorted
  int n;

  cout << "How many records would you like to enter?: ";
  cin >> n;
  cin.ignore(1000, 10);
  cout << endl;

  //cin record for student and store in list
  Student* head = 0; //create empty list

  while ()
  {
    // create a record and read it from console
    Student* aStudent = new Student;

    cout << "What is the student's name?: ";
    cin >> aStudent->name;
    cin.ignore(1000, 10);

    cout << "What is the student's ID #?: ";
    cin >> aStudent->id;
    cin.ignore(1000, 10);

    cout << "What is the student's GPA?: ";
    cin >> aStudent->gpa;
    cin.ignore(1000, 10);
    cout << endl;

    // add record to list, if it's not full
    aStudent->next = head;
    head = aStudent;
  }
    Student* p;
    for (p = head; p; p = p->next)
    {
      cout << "Name = " << left << setw(25) << p->name;
      cout.fill('0');
      cout << " ID = " << right << setw(7) << p->id;
      cout << ", GPA = " << p->gpa << endl;
      cout.fill(' ');
    }

   while(head)
   {
     Student* next = head->next;
     delete head;
     head = next;
   }

  cout << endl;
  return 0;
} // main
try:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
// n = number of records; counter = 0
while (counter < n) 
{  
    ... 
    counter++; 
}

//or
while (true) 
{ 
    ... 
    counter++; 
    if (counter > n) break; 
}


there are other ways I'm sure...
Topic archived. No new replies allowed.