interested in helping????

This is a discussion on interested in helping???? within the C++ Programming forums, part of the General Programming Boards category; Hi all, I am so impressed with you, you do great with this stuff. I am at the end of ...

  1. #1
    Unregistered
    Guest

    interested in helping????

    Hi all, I am so impressed with you, you do great with this stuff. I am at the end of my class, thank goodness. I will always have total respect for you!
    I am completely lost. I think I have messed up and can't even figure out what I am doing wrong and what I need to do to make this compile. Please Please help me!!!!


    //This is a personal address book that contains many enteries.


    #include <iostream.h>

    main()


    {

    struct AddressBook //header for structure and able to enter 10 people

    {



    char Name[15]; //declaring the name and size of 15 characters
    char Address[15];
    char City[25];
    int age[3]; //declaring the age and 3 intergers
    char zip[5];
    char phonenumber[10];

    };



    input (void)


    {


    cout<<"Welcome to my address book!\n"


    cout<<"Enter the information into the address book!\n";

    cout<< Enter the Name: ";
    cin.getline (Name, 20);

    cout<<"Enter the address: ";
    cin.getline (Address, 20);

    cout<<"Enter the City and abbreviated state: ";
    cin.getline (City,30);

    cout<<"Enter the Zip code: ";
    cin.getline (Zip, 6);

    cout<<"Enter the phone number including area code (please do not add a hypen or space): ";
    cin.getline (Phonenumber, 10);

    cout<<"Enter the age of this person: ";
    cin.getline (Age,3);
    AddressbookOutput.write((char *)&AddressbookOutput, sizeof(AddressbookList));


    }

  2. #2
    Registered User
    Join Date
    Jan 2002
    Posts
    559
    Try int main(), and returning 0 (zero).
    What is input(void)? Nothing, as far as I can see.
    How is the info supposed to get into your struct? Name, etc, are struct members, not global or local variables.
    Why do you declare Name as char[15] but cin 20? (assuming that line would work anyway)?
    And why is Age declared as int[3]? An int from -32767 to 32768 (on most systems) is still one int. Doesn't matter if the person is 7 years old, 12, or 153. Just use int.
    Truth is a malleable commodity - Dick Cheney

  3. #3
    Registered User
    Join Date
    May 2002
    Posts
    317
    why don't you try this:

    #include <iostream.h>

    struct AddressBook //header for structure and able to enter 10 people

    {
    char Name[15]; //declaring the name and size of 15 characters
    char Address[15];
    char City[25];
    int age; //declaring the age and 3 intergers
    char zip[5];
    char phonenumber[10];
    };

    int main()
    {
    AddressBook AddBk;

    cout<<"Welcome to my address book!\n";
    cout<<"Enter the information into the address book!\n";
    cout<< Enter the Name: ";
    cin.getline (AddBk.Name, 16);
    cout<<"Enter the address: ";
    cin.getline (AddBk.Address, 16);
    cout<<"Enter the City and abbreviated state: ";
    cin.getline (AddBk.City,26);
    cout<<"Enter the Zip code: ";
    cin.getline (AddBk.Zip, 6);
    cout<<"Enter the phone number including area code (please do not add a hypen or space): ";
    cin.getline (AddBk.Phonenumber, 11);
    cout<<"Enter the age of this person: ";
    cin>>AddBk.age;
    AddressbookOutput.write((char *)&AddressbookOutput, sizeof(AddressbookList));
    return 0;
    }

  4. #4
    Unregistered
    Guest
    Okay, so that was great. I now have only 3 errors,



    What do I need to do to make this output many addresses?? Is that the correct statement (at the end)


    AddressbookOutput.write((char *)&AddressbookOutput, sizeof(AddressbookList));




    thanks, I appreciate your help!!!

  5. #5
    Registered User
    Join Date
    May 2002
    Posts
    317
    I'm assuming you are trying to print to the screen since we you never opened a file so scratch the write thing and:

    cout<<AddBk.Name<<", "<<Addbk.Age<<endl;
    cout<<AddBk.Address<<endl;
    cout<<AddBk.City<<", "<<AddBk.zip<<endl;
    cout<<AddBk.phonenumber<<endl;


    This should work. If you're trying to create a file and write to it we have some stuff to talk about.

  6. #6
    Unregistered
    Guest
    so explain to me in laymans terms what they mean in writing to it???

    Okay, so I did that it and it compiled....yeah!
    Now, I need to keep it going to add more addresses to the book.

    Is this where I I need to have
    ios::in | ios::binary

    ????

    (thanks!)

  7. #7
    Registered User
    Join Date
    May 2002
    Posts
    317
    Alright, to do this the right way we get into an array of structures.
    You define the array like this: AddressBook AddBk[9];
    Now from their just dump the whole cin statements into a for statement.

    Note: You can access each individual structure like this: cin.getline(AddBk[0].Name, 16);

    Also the same thing for the cout statements.

    PS: What do you mean by 'writing to it'?

    Edit: AddBk[0] being the first structure in the array. Also the for statement would define a variable like this:

    for(int i=0, i<10, i++)
    {
    cin.getline(AddBk[i].Name, 16);
    //ect..
    }

    Edit1: The best way to do this would be to break it up into functions( from a good programming practice point of view). If you need help on this just post.
    Last edited by Traveller; 05-05-2002 at 09:59 PM.

  8. #8
    Unregistered
    Guest

    Smile

    thanks so very much! You got me going well. I appreciate your help!!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Anyone interested in helping me out again??
    By xMEGANx in forum C++ Programming
    Replies: 19
    Last Post: 10-04-2007, 02:43 AM
  2. Anyone interested?
    By JarJarBinks in forum Projects and Job Recruitment
    Replies: 7
    Last Post: 09-17-2004, 06:59 AM
  3. for beginner's or anyone interested
    By Iconoklast in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 03-25-2004, 02:45 PM
  4. War with Iraq - Read this article if you're interested
    By Davros in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 01-26-2003, 12:10 AM
  5. Who here would be interested...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 19
    Last Post: 07-19-2002, 09:10 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21