include <iostream>
include<string>

using namespace std;

struct people

{
string fname;
string lname;

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

void output()
{
cout<<people.fname<<people.lname;

}

};

struct birthday{
int day;
int month;
int year;

   void output()

{
cout<<day<<birthday.month<<birthday.year;

}

   void input()

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

};

int i;

int main()

{

 cout<<"Birthday Program"<<endl;

for (i=0;i<2;i++)
{
    cout<<"Enter  First Name and Last Name";
   people.input;

   cout <<"Enter the month, date and year"<<endl;
   birthday.input;

}




  for(i=0;i<2;i++)
   {
       cout<<people.output<<"            "<<birthday.output<<"                "<<endl;
   }






       return 0;

}

Recommended Answers

All 5 Replies

NEED help with this program it's suppoed to input first and last name and then output it on the screen

using structures

You first issue is on the lines that say cin >> people.fname >> people.lname; and cout << people.fname << people.lname;. The token people refers to the type of the structure, not its name, so this results in a syntax error. Since it's a member function, change these lines to cin >> fname >> lname; and cout << fname << lname;, respectively. The same sort of issue appears in birthday::output().

You forgot to actually make an object for the birthday and people structures. When you create a struct, you're only defining a type of object. You create an object in the same way that you make an int for float --- by declaring them as variables. Since you have two of them, you would add this to your main function:

people peoples[2];
birthday birthdays[2];

Again, in your loops, you're treating an struct like an actual object. You're also forgetting to put parenthesis in front of your function calls. Instead of people.input and birthday.input, use peoples[i].input() and birthdays[i].input().

In your second for loop, you're trying to treat functions of type void like they are of type string. This doesn't work and will result in a compiler error. Instead, you should seperate the output like so:

peoples[i].output();
cout << ": ";
birthdays[i].output();
cout << endl;

A few other things: In your output functions, you're forgetting to seperate the last names and the birthday numbers with spaces. Also, the program prompts the user on "month, date and year", but they are ordered as day >> month >> year in your code. That should probably be fixed.

I hope this helps!

Thanks
i got it to work

one more thing

i need to make a vector for possible gift ideas for the names w birthday so far i got

vector <string> Gifts(5);

I would recommend getting rid of the (5) on the end of your declaration of Gifts, as that is usually used for initializing elements when you first create your vector. Do you already know how to use vectors? Online tutorials are everwhere, but I'll give you the run down. What you'll be doing is using the push_back() function to add elements to your vector.

For example, in your case, Gifts.push_back("Cake"); would add "Cake" as a gift idea. When you're printing out your gift ideas, you're obviously going to use a for loop, and Gifts.size() will return the number of elements in your vector. You access the elements the same way you would access the elements of an array.

Thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.