Yaan,
Eliminating the calls to main is correct.
Your logic must be updated to allow your main menu to be shown until exit.
I have provided an update to your code below.
The update also seperates the requests for id and name.
Take care,
Bruce
# include<iostream.h>
# include<stdlib.h>
# include<conio.h>
# include<string.h>
struct ListEntry
{
char name[10];
int idnumber;
struct ListEntry *next;
}
start,*node,*prev;
void add();
void viewdb();
void main()
{
int choice;
do
{
system("cls");
cout << "Choose option from the menu below:\n\n";
cout << "[1] Insert an ID Number and Name\n";
cout << "[2] View the database\n";
cout << "[3] Exit\n";
cout << "\t\tEnter your choice: ";
cin >> choice;
switch(choice)
{
case 1:
add();
break;
case 2:
viewdb();
break;
//case 3:
// exit(1);
}
} while (choice != 3);
}
void add()
{
char choice;
start.next = NULL;
node = &start;
do
{
system("cls");
node->next = (struct ListEntry*) malloc(sizeof(struct ListEntry) );
node = node->next;
cout << "Enter an ID Number:\t";
cin >> node->idnumber;
cout << "Enter a Name:\t";
cin >> node->name;
cout << "Record saved. Input another? (Y, N): ";
cin >> choice;
node->next = NULL;
} while (choice == 'Y' || choice == 'y');
return;
}
void viewdb()
{
node = start.next;
system("cls");
while (node)
{
cout << node->idnumber << "\t" << node->name << endl;
node = node->next;
}
cout << endl;
getch();
return;
}
<< moderator edit: added
code tags: [code][/code] >>