The problem statement is thei 11.17 Write the definition for an array of 50 of t
ID: 3692858 • Letter: T
Question
The problem statement is thei
11.17 Write the definition for an array of 50 of the ThreeTypes structures you declared in Question 11.16.
11.18 Write a loop that stores the floating point value 2.37 in all the elements of the array you defined in Question 11.17.
11.19 Write a loop that stores the character ‘A’ in all the elements of the array you defined in Question 11.17.
11.20 Write a loop that stores the integer 10 in all the elements of the array you defined in Question 11.17.
It's realy just one easy question. But my question is how to get the char to print out when I run the following code, the letter does not print out and the whloe number is not on the same line as it should be. Can you please fix this for me? p.s. oddly enough, if iI ocmment out the real and whole types and just print the char, it works.
#include <iostream>
#include <string>
using namespace std;
int main()
{
union ThreeTypes
{
char letter;
int whole;
double real;
};
ThreeTypes type[50];
for (int i = 0; i < 50; i++)
{
type[i].real = 1.37;
type[i].letter = 'A';
type[i].whole = 10;
cout << type[i].real << " " << type[i].letter << " " << type[i].whole << endl;
}
return 0;
}
Explanation / Answer
Only one fix you need to do:
type[i].real = 1.37;cout << type[i].real << " ";
type[i].letter = 'A';cout << type[i].letter << " ";
type[i].whole = 10;cout << type[i].whole << endl;
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.