Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please help me, this code must be written in C (printf / scanf -- not <>) Thank

ID: 3881672 • Letter: P

Question

Please help me, this code must be written in C (printf / scanf -- not <>)

Thank you.

(1) Prompt the user to input an integer, a double, a character, and a string, storing each into separate variables. Then, output those four values on a single line separated by a space. (2 pts)

Note: This zyLab outputs a newline after each user-input prompt. For convenience in the examples below, the user's input value is shown on the next line, but such values don't actually appear as output when the program runs.

Enter integer:

99

Enter double:

3.77

Enter character:

z

Enter string:

Howdy

99 3.77 z Howdy

(2) Extend to also output in reverse. (1 pt)

Enter integer: 99

Enter double: 3.77

Enter character: z

Enter string: Howdy

99 3.77 z Howdy

Howdy z 3.77 99

(3) Extend to cast the double to an integer, and output that integer. (2 pts)

Enter integer:

99

Enter double:

3.77

Enter character:

z

Enter string:

Howdy

99 3.77 z Howdy

Howdy z 3.77 99

3.77 cast to an integer is 3

Here is the code that is already given to me:

#include

int main(void) {
int userInt;
double userDouble;
// FIXME: Define char and string variables similarly

printf("Enter integer: ");
scanf("%d", &userInt);

// FIXME (1): Finish reading other items into variables, then output the four values on a single line separated by a space


// FIXME (2): Output the four values in reverse


// FIXME (3): Cast the double to an integer, and output that integer

return 0;
}

Explanation / Answer

#include <stdio.h>

int main(void) {
int userInt;
double userDouble;

// FIXME: Define char and string variables similarly
char ch;
char s[100];

printf("Enter integer: ");
scanf("%d", &userInt);

// FIXME (1): Finish reading other items into variables, then output the four values on a single line separated by a space
printf("Enter double: ");
scanf("%lf", &userDouble);
printf("Enter character: ");
scanf(" %c", &ch);
printf("Enter string: ");
scanf("%s", &s);
// FIXME (2): Output the four values in reverse
printf("%s %c %lf %d ",s,ch,userDouble,userInt);

// FIXME (3): Cast the double to an integer, and output that integer
printf("%.2f cast to an integer is %d ",userDouble,(int)userDouble);
return 0;
}

Output:

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote