Question & Answer: Write a C program that accepts as input from the keyboard a floating point number, an integ…..

Write a C program that accepts as input from the keyboard a floating point number, an integer, and a character. Each of these inputs should be preceded by a prompt and stored using individual variable names. Have your program call a function that assembles the input data into a single string. Display the assembled string using the puts ( ) call back in main after the function has completed.

Expert Answer

 

Code:

#include <stdio.h>
#include <string.h>
#define NSIZE 21

char assemble(int, char[], float, char[]);

int main()
{
char name[NSIZE];
int empID;
float hours;
char timeCard[51];

printf(“nPlease enter floating point number “);
scanf(“%f”, &hours);

printf(“nPlease enter integer “);
scanf(“%d”, &empID);

printf(“Please enTer a characTer:”);
scanf(“%s”, name);

assemble (empID, name, hours, timeCard);

printf(“nnAfter assembling the input data into a single string”);
puts(timeCard);

printf(“nn”);

return 0;
}

char assemble (int empID, char name[NSIZE], float hours, char timeCard[51] )
{
sprintf(timeCard, ” %d %s %4.2f hrs”, empID, name, hours);
return (timeCard[51]);
}

Screenshot:

Still stressed from student homework?
Get quality assistance from academic writers!