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

I need help, i am not sure what or where in this Program to put the block commen

ID: 653594 • Letter: I

Question

I need help, i am not sure what or where in this Program to put the block comments and can someone show me what the sample output looks like?

#include <stdio.h>
#include <stdlib.h>

typedef struct {
double dbln;
double dblw;
double dbldis;
double dblcst;
double dblArea;
const double dblLbrcst; // = 0.35;
const double dbltxrt; // = 0.85;
} CARPET;

void carpet_input(CARPET *carpet)
    {
   printf("Length of room (feet)?> ");
   scanf("%lf", &carpet->dbln);
   printf("Width of room (feet)?> ");
   scanf("%lf", &carpet->dblw);
   printf("Customer Discount (%%)");
   scanf("%lf", &carpet->dbldis);
   printf("Cost per Square Foot?> ");
   scanf("%lf", &carpet->dblcst);
carpet->dblArea = carpet->dbln * carpet->dblw;
   }
void carpet_print(CARPET *carpet)
   {
    double cost = carpet->dblArea * carpet->dblcst;
    double labour = carpet->dblArea * carpet->dblLbrcst;
    double sqmCost = carpet->dblcst + carpet->dblLbrcst;
    double totCost = sqmCost * carpet->dblArea;
    double sqmDiscount = sqmCost * carpet->dbldis / 100.0;
    double totDiscount = sqmDiscount * carpet->dblArea;
    double sqmTaxes = sqmCost * carpet->dbltxrt;
    double totTaxes = sqmTaxes * carpet->dblArea;
   printf(" Measurement");
   printf(" %-16.16s %11.2lf", "Length", carpet->dbln);
   printf(" %-16.16s %11.2lf", "Width", carpet->dblw);
   printf(" %-16.16s %11.2lf", "Area", carpet->dbln * carpet->dblw);
   printf(" DESCRIPTION       COST/SQ.FT CHARGE");
   printf(" %-16.16s %11.2lf %10.2lf", "Carpet", carpet->dblcst,       cost);
   printf(" %-16.16s %11.2lf %10.2lf", "Labor", carpet->dblLbrcst, labour);
   printf(" %-16.16s %11.2lf %10.2lf", "INSTALLED PRICE $", sqmCost, totCost);
    printf(" %-16.16s %11.2lf %10.2lf", "Discount", sqmDiscount, totDiscount);
    printf(" %-16.16s %11.2lf %10.2lf", "SUBTOTAL", sqmCost - sqmDiscount, totCost - totDiscount);
    printf(" %-16.16s %11.2lf %10.2lf", "Taxes: ", sqmTaxes, totTaxes);
    printf(" %-16.16s %11.2lf %10.2lf", "Total: ", sqmCost * carpet->dbltxrt + sqmCost - sqmDiscount, totCost * carpet->dbltxrt + totCost - totDiscount);
   }

int main(void)
   {
   CARPET carpet = {
       .dbln = 0.0,
       .dblw = 0.0,
       .dbldis = 0.0,
       .dblLbrcst = 0.35,
       .dbltxrt = 0.085
       };
   carpet_input(&carpet);
   carpet_print(&carpet);
   return 0;
   }

Explanation / Answer

Below is the code with block comments:-

#include <stdio.h>
#include <stdlib.h>

typedef struct {   /*define a struct named CARPET*/
double dbln;       /*declare the structure varaiables*/
double dblw;
double dbldis;
double dblcst;
double dblArea;
const double dblLbrcst; // = 0.35;
const double dbltxrt; // = 0.85;
} CARPET;   /*name the structure as CARPET*/

void carpet_input(CARPET *carpet)   /*method to accept input data regarding the carpet from user*/
    {
   printf("Length of room (feet)?> ");
   scanf("%lf", &carpet->dbln);
   printf("Width of room (feet)?> ");
   scanf("%lf", &carpet->dblw);
   printf("Customer Discount (%%)");
   scanf("%lf", &carpet->dbldis);
   printf("Cost per Square Foot?> ");
   scanf("%lf", &carpet->dblcst);
carpet->dblArea = carpet->dbln * carpet->dblw;
   }
void carpet_print(CARPET *carpet)   /*method to calculate and print the CARPET cost,labour charge,cost/sq metre,total cost,discount/ sq meter,total discount,tax/ sq metre,total tax*/
   {
    double cost = carpet->dblArea * carpet->dblcst;
    double labour = carpet->dblArea * carpet->dblLbrcst;
    double sqmCost = carpet->dblcst + carpet->dblLbrcst;
    double totCost = sqmCost * carpet->dblArea;
    double sqmDiscount = sqmCost * carpet->dbldis / 100.0;
    double totDiscount = sqmDiscount * carpet->dblArea;
    double sqmTaxes = sqmCost * carpet->dbltxrt;
    double totTaxes = sqmTaxes * carpet->dblArea;
   printf(" Measurement");
   printf(" %-16.16s %11.2lf", "Length", carpet->dbln);
   printf(" %-16.16s %11.2lf", "Width", carpet->dblw);
   printf(" %-16.16s %11.2lf", "Area", carpet->dbln * carpet->dblw);
   printf(" DESCRIPTION       COST/SQ.FT CHARGE");
   printf(" %-16.16s %11.2lf %10.2lf", "Carpet", carpet->dblcst,       cost);
   printf(" %-16.16s %11.2lf %10.2lf", "Labor", carpet->dblLbrcst, labour);
   printf(" %-16.16s %11.2lf %10.2lf", "INSTALLED PRICE $", sqmCost, totCost);
    printf(" %-16.16s %11.2lf %10.2lf", "Discount", sqmDiscount, totDiscount);
    printf(" %-16.16s %11.2lf %10.2lf", "SUBTOTAL", sqmCost - sqmDiscount, totCost - totDiscount);
    printf(" %-16.16s %11.2lf %10.2lf", "Taxes: ", sqmTaxes, totTaxes);
    printf(" %-16.16s %11.2lf %10.2lf", "Total: ", sqmCost * carpet->dbltxrt + sqmCost - sqmDiscount, totCost * carpet->dbltxrt + totCost - totDiscount);
   }

int main(void)
   {
   CARPET carpet = {
       .dbln = 0.0,
       .dblw = 0.0,
       .dbldis = 0.0,
       .dblLbrcst = 0.35,
       .dbltxrt = 0.085
       };   /*create a CARPET type object named carpet*/
   carpet_input(&carpet);   /*call method carpet_input to accept input data*/
   carpet_print(&carpet);   /*call method carpet_print to print the calculated details of carpet*/
   return 0;   /*exit from program*/
   }

Below is the input and output values for the program:-

Input:-

Length of room (feet)?> 1
Width of room (feet)?> 2
Customer Discount (%) 4
Cost per Square Foot?> 6


Output:-

Measurement
Length   1.00
Width   2.00
Area   2.00

DESCRIPTION   COST/SQ.FT    CHARGE
Carpet                          6.00       12.00
Labor                           0.35       0.70
INSTALLED PRICE        6.35       12.70
Discount                       0.25       0.51
SUBTOTAL                   6.10       12.19
Taxes:                          0.54       1.08