1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
#include <iostream>
#include <string>
int main()
{
// Define a new datatype R_Colors and
// the values associated with R_Colors.
enum R_Colors {Black, Brown, Red, Orange, Yellow,
Green, Blue, Purple, Gray, White,
Gold, Silver, None};
const std::string R_Color_Names [] =
{
"black", "brown", "red", "orange", "yellow", "green",
"blue", "purple", "gray", "white", "gold", "silver"
};
R_Colors Band[4] ;
const unsigned BandSize = sizeof(Band) / sizeof(Band[0]) ;
for ( unsigned i=0 ; i < BandSize ; ++i )
{
std::cout << "Please enter\n" ;
for ( unsigned j=0; j < sizeof(R_Color_Names) / sizeof(R_Color_Names[0]); ++j )
std::cout << '\t' << j << " for " << R_Color_Names[j] << '\n' ;
int input ;
if ( (std::cin >> input) && input >= Black && input < None )
Band[i] = static_cast<R_Colors>(input) ;
else
{
std::cerr << "ERROR: Invalid input\n" ;
return 0 ;
}
}
for ( unsigned i=0; i < BandSize ; ++i )
{
std::cout << "Band[" << i << "] is " << Band[i] ;
std::cout << " (" << R_Color_Names[Band[i]] << ")\n" ;
}
}
|