We're a community of 1.1M IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,080,642 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

C++ outputng wrong info quick help

#include <iostream>
#include<string>
#include<vector>
using namespace std;


struct Names
{
    string fname;
    string lname;

void output()

{
    cout<<fname<<" "<<lname;

}

void input()
{
    cin>>fname>>lname;
}


};



struct birth_info
{
    int month;
    int day;
    int year;



    void input()

{
    cin>>month>>day>>year;

}

        void output()

{
    cout<<month<<"/"<<day<<"/"<<year;

}





};





    int main()
    {

        string name[3];
        int i;
        int day[3];
        int month[3];
        int year[3];



        Names names[3];
        birth_info birth[3];
        cout<<"Welcome to The Birthday Program v2"<<endl;


     for (int i=0;i<=2;i++)


     {
         cout<<"Enter First and Last Name"<<endl;
         names[i].input();

         cout<<"The Day"<<endl;
            cin>>day[i];

         cout<<"The Month"<<endl;
            cin>>month[i];

         cout<<"The Year"<<endl;
            cin>>year[i];

     }





           for(i=0;i<3;i++)
        {
                names[i].output();
                cout << ": ";
                birth[i].output();
                cout << endl;
        }


    vector <string> Gifts;

    Gifts.push_back("Guitar");
    Gifts.push_back("Gift Card");
    Gifts.push_back("Moviees");
    Gifts.push_back("books");
    Gifts.push_back("xbox");


int o;
cout <<"Gift Ideas: "<<endl;
for (o=0; o<Gifts.size(); o++)
cout << Gifts[o] << " " <<endl;
cout <<endl;





            return 0;
    }

ok so when i run the program the out put for the last array is supposed to output everyones birth day but it doesn't it outputs the variable addreses or something

any help would be helpfull

thanks#
2
Contributors
3
Replies
38 Minutes
Discussion Span
8 Months Ago
Last Updated
5
Views
orar
Newbie Poster
11 posts since Apr 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

Please point out where you're calling birth[i].input().

deceptikon
Challenge Accepted
Administrator
3,502 posts since Jan 2012
Reputation Points: 822
Solved Threads: 481
Skill Endorsements: 58
#include <iostream>
#include<string>
#include<vector>
using namespace std;


struct Names
{
    string fname;
    string lname;

void output()

{
    cout<<fname<<" "<<lname;

}

void input()
{
    cin>>fname>>lname;
}


};



struct birth_info
{
    int month;
    int day;
    int year;



    void input()

{
    cin>>month>>day>>year;

}

        void output()

{
    cout<<month<<"/"<<day<<"/"<<year;

}





};





    int main()
    {

        string name[3];
        int i;
        int day[3];
        int month[3];
        int year[3];



        Names names[3];
        birth_info birth[3];
        cout<<"Welcome to The Birthday Program v2"<<endl;


     for (int i=0;i<3;i++)


     {
         cout<<"Enter First and Last Name"<<endl;
         names[i].input();

         cout<<"Enter The Day, the month and year"<<endl;
         cin>>birth[i].input();


     }





           for(i=0;i<3;i++)
        {
                names[i].output();
                cout << ": ";
                birth[i].output();
                cout << endl;
        }


    vector <string> Gifts;

    Gifts.push_back("Guitar");
    Gifts.push_back("Gift Card");
    Gifts.push_back("Moviees");
    Gifts.push_back("books");
    Gifts.push_back("xbox");


int o;
cout <<"Gift Ideas: "<<endl;
for (o=0; o<Gifts.size(); o++)
cout << Gifts[o] << " " <<endl;
cout <<endl;





            return 0;
    }

OK ichanged the code for the birth info but another error came up on the gift code

orar
Newbie Poster
11 posts since Apr 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

but another error came up

If you're going to paste over 100 lines of poorly formatted code with every post then I'll have to ask that you fix the formatting. If you're going to say vague things like "it doesn't work" or "I'm getting an error", I'll direct you here.

kthxbye.

deceptikon
Challenge Accepted
Administrator
3,502 posts since Jan 2012
Reputation Points: 822
Solved Threads: 481
Skill Endorsements: 58

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page generated in 0.2882 seconds using 2.69MB