I just now started learning structures and I have my program working, but how can I improve it so it incorporates eye color (using enumerated types), and full street address.
For example the user will enter 123 Oak Street San Antonio TX and it returns the address
Enter first and last name:
random name
Enter Date of Birth as MM DD YYYY
08 21 1999
Enter Address: redwood sacramento CA
Expiration Date: 07 12 2023
Enter weight 130
Enter height: 5'10
random name
Birthdate: 8/21/1999
Address redwood sacramento CA
Expiration Date: 7/12/2023
Weight: 130
height: 5'10
enum EyeColor
{
EYE_BLUE,
EYE_GREEN,
EYE_BROWN,
EYE_BLACK,
...
};
const std::string EyeColorNames[] =
{
"blue",
"green",
"brown",
"black",
...
};
std::ostream& operator << ( std::ostream& outs, const EyeColor& color )
{
return outs << EyeColorNames[color];
}
std::istream& operator >> ( std::istream& ins, EyeColor& color )
{
std::string s;
if (ins >> s)
{
using std::begin;
using std::end;
auto iter = std::find( begin(EyeColorNames), end(EyeColorNames ), s );
if (iter == end(EyeColorNames))
{
ins.setstate( std::ios::failbit );
return ins;
}
color = (EyeColor)std::distance( begin(EyeColorNames), iter );
}
return ins;
}
Obnoxious, isn’t it?
This code is actually kind of fragile, too. It fails the ODR. And there are waaaay more eye colors than people tend to think. Enums stink.