Instructions Create a program called formattedIO.c that does the following: 1.Pr
ID: 3638225 • Letter: I
Question
InstructionsCreate a program called formattedIO.c that does the following:
1.Prompt the user and accept the following 4 types of values from a single input line: char int char float
2.Display the values that were read in (1)
3.Prompt the user and accept the following types of values from a single input line: string char float int char
4.Display the values that were read in (3)
5.Prompt the user and accept an integer value
6.Display the value read in (5) in a right-justified field of width 15, with leading zeroes
7.Prompt the user and accept a float value
8.Display the value read in (7) in a right-justified field of width 15, with 2 decimal points of precision, and leading spaces
Explanation / Answer
#include <stdio.h>
#include <iomanip>
int main()
{
//required variables to read input and display
char ch1, ch2, s[25];
int n;
float f;
//reads a character, integer, character and float value
printf("Enter char int char float: ");
scanf("%c %d %c %f", &ch1, &n, &ch2, &f);
//displays the read data
printf("You entered: '%c' %d '%c' %.3f", ch1, n, ch2, f);
//reads a string, character, float, integer, and character value
printf(" Enter string char float int char: ");
scanf("%s %c %f %d %c", s, &ch1, &f, &n, &ch2);
//displays the read data
printf("You entered: "%s" '%c' %0.3f %d '%c'", s, ch1, f, n, ch2);
//reads an integer value
printf(" Enter an integer value: ");
scanf("%d", &n);
//displays it in a right justification of width 15, with leading zeros
printf("You entered: %015d", n);
//reads a float value
printf(" Enter a float value: ");
scanf("%f", &f);
//displays it in a right justification of width 15, with leading spaces
//and 2 decimal points of precision.
printf("You entered: %15.2f", f);
printf(" ");
return 0;
}