Complete this program using the following declarations, the TypeString array, and the main().
enum Type{Even, Odd};
union Value
{
int i;
double d;
};
struct Number
{
Type type;
Value value;
};
const string TypeString[2] = {"even","odd"};
int main()
{
Number var[10];
for (int i= 0; i < 10; i++)
assign(var[i]);
for (int i= 0; i < 10; i++)
print(var[i]);
}
You will need to add assign() and print() functions. The assign() function generates a random int between 1 and 100. If the int is even, it is stored in the Value union and Even in the Type. If the in is odd, then the square root of the random number is stored in the Value union and Odd in the Type. The output from the print function should look like the following. Make use of the TypeString array in your print() function.
Number is even 42
Number is even 68
Number is odd 5.91608
Number is odd 1
Number is even 70
Number is odd 5
Number is odd 8.88819
Number is odd 7.68115
Number is odd 7.93725
Number is odd 8.06226