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]
3 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]3 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
What did Stalin hope the Western powers would do because of the blockade?​
Elodia [21]

Answer:

Stalin's plan was to cut western Germany off from its capital

Explanation:

Stalin's plan was to cut western Germany off from its capital so that the new government, based in Berlin, could not control its territory in western Germany. He hoped that this would prove that a divided Germany would not work in practice.

6 0
3 years ago
PLSSS HELLLP!!! THE CROWN WILL BE REWARDED FOR THE CORRECT ANSWER!!!
Sergio039 [100]

Answer:

The audience

Explanation:

The correct option is - The audience

Reason -

When writing a technical document -

Always describe things in technical terms.

Write for your readers.

Describe things exactly as they're described to you by subject matter experts.

Technical writing :

Addresses particular readers.

Helps readers solve problems.

4 0
3 years ago
You are comparing two properties for lease. The first, A, is all-inclusive at $4,000 per month. The second, B, is $2,300 per mon
Lemur [1.5K]
Take 4,000 times 12 to get 48,000. that’s how much A costs.

B is a little harder. you have to take (2,300+300)x12+(4*250). this equals $32,100

the correct answer would be B.
6 0
3 years ago
Identify the term that refers to the right to control access to ourselves and to our personal information.
g100num [7]

Answer:

Privacy

Explanation:

In the privacy control access mechanism it control the data of the personal information.The model P-RBAC that is the framework of key component that extended the RBAC model that gives the complex  policy of privacy such as obligations.In the P-RBAC we defined the privacy awareness permission.

The privacy control access mechanism giving the right to control the personal information.

7 0
3 years ago
Select the correct answer.
Katen [24]

Answer: D

Explanation: I don't know I hope u get it right

3 0
2 years ago
Other questions:
  • You are looking to buy a laptop on a budget and want to save money by not purchasing an extended service agreement with the manu
    13·1 answer
  • Data administration is a special organizational function that manages the policies and procedures through which data can be mana
    9·1 answer
  • A(n) __________ is a set of technologies used for exchanging data between applications and for connecting processes with other s
    14·2 answers
  • Convert the decimal number -12 to hexadecimal (2's complement)
    5·1 answer
  • Which bitwise operation has the same effect as multiplying a by 16?
    6·2 answers
  • Omega Software Inc. is currently running a training program for employees to upgrade their software skills so that they are able
    10·1 answer
  • I prefer a job where I am praise for good performance or I am accountable for results
    13·1 answer
  • Write an algorithm to show whether a given number is even or odd.
    14·1 answer
  • You are shooting water balloons with a slingshot. One water balloon goes twice as far as another. Which of the following is the
    8·1 answer
  • What is draft pls help me​
    15·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!