I have the following code which works, however not all of the decimals and place
ID: 3631021 • Letter: I
Question
I have the following code which works, however not all of the decimals and place values line up with the lines above and below. I have been messing with it and just can't seem to get it. the issue is under output where is says carpet and labor. if your per unit cost of the carpet is 10.00 or more the decimals for that and the .35 for labor don't line up. The code is below:
// Carpeting Bill//
#include <stdafx.h>
#include <stdio.h>
//define the constants//
#define LABOR_COST 0.35
#define TAX_RATE 8.5
int main ()
{
// Defining variables //
int length, width, area, discount;
double unitprice, total;
// Get keyboard input from user //
printf(" Length of room (feet)? ");
scanf("%d",&length);
printf("Width of room (feet)? ");
scanf("%d",&width);
printf("Customer discount (percent)? ");
scanf("%d",&discount);
printf("Cost per suqare foot (xxx.xx)? ");
scanf("%lf",&unitprice);
// Compute and display the results on the fly //
// Measurements section, measurements displayed //
printf(" MEASUREMENT ");
printf(" Length %d ft", length);
printf(" Width %d ft", width);
area = length * width;
printf(" Area %d square ft ", area);
// Charges section, charges calculated and displayed //
printf(" CHARGES ");
printf(" DESCRIPTION COST/SQ.FT. CHARGE ");
printf("=========== =========== ================= ");
total = unitprice * (double)area;
printf("Carpet %4.2f $%7.2f", unitprice, total);
printf(" Labor %4.2f %8.2f", LABOR_COST, LABOR_COST*(double)area);
printf(" ================= ");
total = total + LABOR_COST*(double)area;
printf("INSTALLED PRICE $%7.2f ", total);
printf("Discount %d %c %8.2f",discount,37, total*((double)discount/100.0));
printf(" ================= ");
total = total - (total*((double)discount/100.0));
printf("Subtotal $%7.2f", total);
printf(" Tax %8.2f", total*(TAX_RATE/100.0));
total = total + total*(TAX_RATE/100.0);
printf(" Total $%7.2f ", total);
return 0;
}
Explanation / Answer
please rate - thanks
your field widths weren't large enough. I changed them from 7 and 8 to 9 and 10
did a few other minor changes too
#include <stdio.h>
//define the constants//
#define LABOR_COST 0.35
#define TAX_RATE 8.5
int main ()
{
// Defining variables //
int length, width, area, discount;
double unitprice, total;
// Get keyboard input from user //
printf(" Length of room (feet)? ");
scanf("%d",&length);
printf("Width of room (feet)? ");
scanf("%d",&width);
printf("Customer discount (percent)? ");
scanf("%d",&discount);
printf("Cost per suqare foot (xxx.xx)? ");
scanf("%lf",&unitprice);
// Compute and display the results on the fly //
// Measurements section, measurements displayed //
printf(" MEASUREMENT ");
printf(" Length %d ft", length);
printf(" Width %d ft", width);
area = length * width;
printf(" Area %d square ft ", area);
// Charges section, charges calculated and displayed //
printf(" CHARGES ");
printf(" DESCRIPTION COST/SQ.FT. CHARGE ");
printf("=========== =========== ================= ");
total = unitprice * (double)area;
printf("Carpet %6.2f $%9.2f ", unitprice, total);
printf("Labor %6.2f %10.2f", LABOR_COST, LABOR_COST*(double)area);
printf(" ================= ");
total = total + LABOR_COST*(double)area;
printf("INSTALLED PRICE $%9.2f ", total);
printf("Discount %d %c %10.2f",discount,37, total*((double)discount/100.0));
printf(" ================= ");
total = total - (total*((double)discount/100.0));
printf("Subtotal $%9.2f", total);
printf(" Tax %10.2f", total*(TAX_RATE/100.0));
total = total + total*(TAX_RATE/100.0);
printf(" Total $%9.2f ", total);
getch();
return 0;
}