I've gotten feedback from my instructor to modify my code because it contains poor design techniques. I need to add a " return " after each function without it going back to " main " and also to avoid the use of global headers.
I've tried to modify it several ways, but I cannot seem to do it. Any help would be greatly appreciated as I am still learning the c++ language.
# 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;
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);
}
}
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 and Name:\t";
cin>>node->idnumber>>node->name;
cout<<"Record saved. Input another? (Y,N): ";
cin>>choice;
node->next=NULL;
}
while(choice=='Y'||choice=='y');
main();
}
void viewdb()
{
node=start.next;
system("cls");
while(node)
{
cout<<node->idnumber<<"\t"<<node->name<<endl;
node=node->next;
}
cout<<endl;
getch();
main();
}
<< moderator edit: added code tags: [code][/code] >>