1. ## Struct Problem

Code:
```#include <iostream>
using namespace std;

int main()

{

int index;

struct DOB{
int day;
int month;
int year;
};

DOB date[9];

for (index = 0; index < 1; index ++)
{
cout << endl << "please enter the day ";
cin >> date[index].day;
cout << endl << "please enter the month ";
cin >> date[index].month;
cout << endl << "please enter the year ";
cin >> date[index].year;
}

cout << date[1];

}```
I'm fairly new to using structs so bare with me. From what i've read this seems ok, but when it's run it says there is an error with the struct.
I realise the values of the array are wrong at the moment but that's just until I get the actual code working.

Can anybody help me?

Thanks.

2. main should return 0.

Code:
`cout << date[1];`
The streams library doesn't know how to output a struct DOB, you need to tell it how. e.g. write an operator<< such as

Code:
```#include <iostream>
using namespace std;

struct DOB
{
int day;
int month;
int year;
};

ostream& operator<<(ostream& os, const DOB& dob);

int main()
{
int index;
DOB date[9];

for (index = 0; index < 1; index ++)
{
cout << endl << "please enter the day ";
cin >> date[index].day;
cout << endl << "please enter the month ";
cin >> date[index].month;
cout << endl << "please enter the year ";
cin >> date[index].year;
}

cout << date[0];

return(0);
}

ostream& operator<<(ostream& os, const DOB& dob)
{
os << dob.day << "/" << dob.month << "/" << dob.year << endl;
return(os);
}```

3. Code:
```for (index = 0; index < 1; index ++)
{
...
}

cout << date[1];```
index was in 0 to 0 range
date[1] is not initialized

4. >> main should return 0.
Why? It isn't necessary.

5. Originally Posted by Daved
>> main should return 0.
Why? It isn't necessary.
If he is in school then marks will likely be deducted

6. >If he is in school then marks will likely be deducted
That's debatable, and completely irrelevant.

7. >> If he is in school then marks will likely be deducted
If marks will be deducted then of course it should be included. But since leaving it out is still completely standard and correct code, then perhaps such an instructor should re-think the grading guidelines.

8. for a beginner, instead of creating overloaded operators it might be easier to understand to just use the normal struct way

Code:
`cout << date[0].day << ' ' << date[0].year; // etc`

9. >> main should return 0.
Why? It isn't necessary.

>>If he is in school then marks will likely be deducted
That's debatable, and completely irrelevant.
I haven't met a Prof that took points off due to this. I believe for a beginner, it's good to include it in code to grasp the concept of functions and the concept of them returning values whatever its value.

Maniac, there is nothing wrong with the struct, but with the way in which you're trying to output its members values as others have already demonstrated:
Code:
```#include <iostream>
using namespace std;

int main()
{
int index;

struct DOB {
int day;
int month;
int year;
};

DOB date[9];

for ( index = 0; index < 1; index++ ) {
cout << endl << "please enter the day ";
cin >> date[ index ].day;
cout << endl << "please enter the month ";
cin >> date[ index ].month;
cout << endl << "please enter the year ";
cin >> date[ index ].year;
}

cout << date[ 0 ].day << " " << date[ 0 ].month << " " << date[ 0 ].year << endl;

return 0;
}```

10. Originally Posted by CaptainMorgan
I haven't met a Prof that took points off due to this. I believe for a beginner, it's good to include it in code to grasp the concept of functions and the concept of them returning values whatever its value.

Maniac, there is nothing wrong with the struct, but with the way in which you're trying to output its members values as others have already demonstrated:
Code:
```#include <iostream>
using namespace std;

int main()
{
int index;

struct DOB {
int day;
int month;
int year;
};

DOB date[9];

for ( index = 0; index < 1; index++ ) {
cout << endl << "please enter the day ";
cin >> date[ index ].day;
cout << endl << "please enter the month ";
cin >> date[ index ].month;
cout << endl << "please enter the year ";
cin >> date[ index ].year;
}

cout << date[ 0 ].day << " " << date[ 0 ].month << " " << date[ 0 ].year << endl;

return 0;
}```

Cheers for that! I see were I was going wrong now.

I do know you're meant to put return 0, but like it's been said, it's not essential so I left it out here.

11. Not that it matters, but structs and classes are usually delcared outside the main function

Code:
```struct Foo
{
int x;
};

int main ( void )
{
Foo fo;

fo.x = 5;

cout << "value of x: " << fo.x << endl;

return 0;
}```