View Single Post
Old 04-14-2005, 11:07 AM   #1 (permalink)
Popplewell
Registered User
 
Join Date: Apr 2005
Posts: 5
Popplewell is on a distinguished road
Newbie with a dynamic problem

I am just starting a computing course and have been doing an assignment on dynamic arrays. I have some code but i don't see where I am going wrong, if someone could show me the error of my ways i would be really greatful. Any advice will be much appreciated.
It's a phone book entry system that needs a number of entry's then be able to search for a name and present its phone number or an unavailable message.

Code:
//Data Strucures Assignment 1 #include <iostream.h>
#include <cstring.h>
#include <conio.h>


struct contact{
 string name;
 string number;
              };

 void main(){
 struct contact *entry;
 int i,number;
 char namesearch;
 char c;
 cout<<"How many entrys? ";
 cin>>number;
 cin.get(c);
 entry = new struct contact[number];

 for(i=1;i<number;i++){
 cout<<"Name ";
 getline(cin, entry[i].name);
 cout<<"Phone number ";
 cin>>entry[i].number;
 cin.get(c);
                           };
 clrscr();
 for (i=1;i<number;i++);
 cout<<entry[i].name<<" "<<entry[i].number<<endl;

 cout<<"Search for a contact: "<<endl;
 cout<<"(Press Z to stop) Contact Name: ";
 cin.getline(namesearch);
 while (char(namesearch, "Z")<0);{
 clrscr();
 string(entry[0].name = namesearch);
 i = number;
 while (char(entry[i].name = namesearch) !=0)
 i--;
 if (i==0)
 cout<<"Not available"<<endl;
 cout<<"Press enter to search again";
 cin.get(c);
 }
 else
 {
 cout<<"Conatact Name: "<<entry[i].name<<endl;
 cout<<"Phone Number: "<<entry[i].number<<endl;
 cout<<"Press enter to search again";
 cin.get(c);
 }
 clrscr();
 cout<<"Search for a contact "<<endl;
 cout<<"(Press Z to stop) Contact Name: "<<endl;
 cin.getline(namesearch);
 }

Thanks for your time x

Last edited by Valmont; 04-14-2005 at 12:16 PM.
Popplewell is offline   Reply With Quote