1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
hichkok12 [17]
2 years ago
7

Create union integer with members char c, short s, int i and long b. Write a program that inputs the values of type char, short,

int, and long and stores the values in union variables of type union integer. Each union variable should be printed as a char, a short, an int and a long. D the values always print correctly? Also create pseodocode or flowchart.
Here is the feedback that I received when I originally turned this in:
I have the following concerns: You need to save your program file with a .c extension. You should declare your union above the main module and then utilize it from within this portion. You have declared the union and then created a function definition prior to entering the main() function.
Here is the original code provided by homework help: Thanks in advance
#include
union myUnion {
char c;
short s;
int i;
long l;
};
void print(myUnion u) {
printf("As a character: %c\n", u.c);
printf("As a short: %hd\n", u.s);
printf("As an int: %d\n", u.i);
printf("As a long: %ld\n\n", u.i);
}
int main() {
myUnion u;
printf("Please enter a character: ");
scanf("%c", &(u.c));
print(u);
printf("Please enter a short: ");
scanf("%hd", &(u.s));
print(u);
printf("Please enter an int: ");
scanf("%d", &(u.i));
print(u);
printf("Please enter a long: ");
scanf("%ld", &(u.l));
print(u);
return 0;
Computers and Technology
1 answer:
Tom [10]2 years ago
5 0

Answer:

The updated program in C is as follows:

#include <stdio.h>

union myUnion{ char c; short s; int i; long l; };

int main(){

   union myUnion inputs;

   printf("Character: ");    scanf("%c", &inputs.c);

   printf("Output: %c", inputs.c);

   printf("\nShort: ");    scanf("%hd", &inputs.s);

   printf("Short: %hd", inputs.s);

   printf("\nInteger: ");    scanf("%d", &inputs.i);

   printf("Output: %d", inputs.i);

   printf("\nLong: ");    scanf("%ld", &inputs.l);

   printf("Long: %ld", inputs.l);

   return 0;

   }

The pseudocode is as follows:

Function union myUnion {

character; short; int; long

}

main() {

myUnion inputs;

Input inputs.c;  Print inputs.c

Input inputs.s; Print inputs.s

Input inputs.i; Print inputs.i;

Input inputs.l; Print inputs.l

}

Explanation:

This defines the union function

<em>union myUnion{ char c; short s; int i; long l; };</em>

The main begins here

int main(){

This calls the union function to main

   union myUnion inputs;

This prompts and gets input for character variable

   printf("Character: ");    scanf("%c", &inputs.c);

This prints the character input

   printf("Output: %c", inputs.c);

This prompts and gets input for short variable

   printf("\nShort: ");    scanf("%hd", &inputs.s);

This prints the short input

   printf("Short: %hd", inputs.s);

This prompts and gets input for integer variable

   printf("\nInteger: ");    scanf("%d", &inputs.i);

This prints the integer input

   printf("Output: %d", inputs.i);

This prompts and gets input for long variable

   printf("\nLong: ");    scanf("%ld", &inputs.l);

This prints the long input

   printf("Long: %ld", inputs.l);

   return 0;

   }

You might be interested in
How do I delete my account on Brainly? It says I must enter my password to do so, but I never set up a password. When I try the
Lady_Fox [76]
Try using your email account password
8 0
2 years ago
Why was the first computer developed? a.) for personal use, b.) for military purposes, c.) for transportation, d.) for communica
IgorLugansk [536]
B) For Military Purposes but around the 1970s they became widely available to consumers.
5 0
3 years ago
Question 1
weeeeeb [17]

Answer:

-6.4

Explanation:

just divide -32 by 5 and you will get your answer of -6.4

7 0
3 years ago
You are studying for a test tomorrow. Your friends invite you to
lapo4ka [179]

Answer: C

Explanation:

7 0
3 years ago
The source ip address is 164.109.28.3 subnet mask of 255.255.128.0 network address is
Sergeu [11.5K]
164.109.0.0/17




-------------------------------------------
6 0
2 years ago
Other questions:
  • Which type of object is used to organize and store data in Microsoft access 2013
    5·2 answers
  • What is the aperture and how does it impact sunrise/sunset photos? What is generally considered an ideal aperture for sunrise/su
    5·2 answers
  • Drag the tiles to the correct boxes to complete the pairs.
    13·1 answer
  • Write a calculator program that keeps track of a subtotal like real calculators do. Start by asking the user for an initial numb
    12·1 answer
  • There is an enormous amount of information on the Internet that is automatically separated into good content and not-so-good con
    15·1 answer
  • A database administrator (DBA) must have a clear understanding of the fundamental business of an organization, be proficient in
    12·1 answer
  • What devices gives input​
    5·1 answer
  • WILL GIVE BRAINLIEST!!!!!!!
    14·1 answer
  • Who programmed the UNIVAC computer and literally "debugged" the first computer?
    13·2 answers
  • After turning on your computer ,it prompts you to type a password to continue the boot process. However ,you forgot the password
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!