if user inputs 1, then code has to list the student #include <iostream>
name and id already in the code.
if user inputs 2, then the code should allow the user to add student name to the linked list and id will be automaticallly inserted as (previous id+1).
if usre inputs 3, response should be exit the code.
however, my program, even though it compiles, it doesnt workn properly..
#include <cstdlib>
using namespace std;
struct node
{ char name[20]; // Name of up to 20 letters
int id; // D.O.B. would be better
node *nxt; // Pointer to next node
};
int main()
{
node *start_ptr = NULL;
node * temp = new node;
if (start_ptr == NULL)
start_ptr = temp;
temp = start_ptr;
int n;
cout<<"enter:";
cin>>n;
while (temp != NULL);
{
if (temp == NULL)
{cout << "End of list" << endl;
return 1;
}
switch (n){
case 1: cout<<"Name : something"<<" "<<"id: 1"<<endl;break;
case 2: cout << "Name : ";
cin>>temp->name;
cout << "id : ";
cin>>temp->id;
cout << endl;break; // Blank line
// Move to next node (if present)
temp = temp->nxt;
case 3: return 1;
}
}
system ("pause");
return 0;
}
any help would be much appreciated.

Ask A New Question
Reply





MultiQuote







|