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?
#include <iomanip>
#include <iostream>
#include <string>
usingnamespace 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