Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6591149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:23:17+00:00 2026-05-25T17:23:17+00:00

I’m very new to this, so please bear with me. For a coding C

  • 0

I’m very new to this, so please bear with me. For a coding C class, we’re to use a total of nine functions and a header file (we’re calling it my.h) to collect the length and width of a room (ints), the percent discount (also an int), and the unit price of the carpet (a double). We’re to use the input to calculate the total cost to install the carpet. I can get the length, width and area to print, but not the unit price. It prints frin from the Read_Data.c and the Calc_Value.c functions, but not in Install_Price.c, which is called in Calc_Value.c. unit_price is read at the same time as length and width, but somehow, its not passed correctly. I’m not sure why. Maybe it does require a different pointer. Any help would be immensely appreciated. I’ve read my book and spoken to my professor and classmates, as well as searched the Internet, but I haven’t found anything that helps. The code for Install_Price is:

/*This function calculates the cost of the carpet and the labor cost in order to    
calculate the installed price.*/

#include "my.h"

void Install_Price (int length, int width, int unit_price, int* area, 
double* carpet_cost, double* labor_cost, double* installed_price)

{

printf("\nThe unit price is %7.2f.\n", *unit_price);

*area = length * width;
*carpet_cost = (*area) * unit_price;

printf("The carpet cost is %7d x %7.2f = %7.2f.\n", *area, unit_price, *carpet_cost);

*labor_cost = (*area) * LABOR_RATE;
*installed_price = (*carpet_cost) + (*labor_cost);

return;
}

Please note, the printf statements here are just to try and figure out where I went wrong with unit_price. Below, I included the my.h header code, main.c, and the functions that it calls upto Install_Price.c. Again, thanks for all your help!

my.h

#include <stdio.h>
void Read_Data(int* length, int* width, int* percent_discount, double* 
unit_price);

void Calc_Values(int length, int width, int percent_discount, double 
unit_price, int* area, double* carpet_cost, double* labor_cost, double* 
installed_price, double* discount, double* subtotal, double* tax, 
double* total);

void Install_Price(int length, int width, int unit_price, int* area, double*      
carpet_cost, double* labor_cost, 
double* installed_price);

void Subtotal (int percent_discount, double installed_price, double* discount, 
double* subtotal);

void Total (double subtotal, double* tax, double* total);

void Print (int length, int width, int area, double unit_price, double carpet_cost,    
double labor_cost, double 
installed_price, int percent_discount, double discount, double subtotal, double tax,   
double total);

void Print_Measurements (int length, int width, int area);

void Print_Charges (double unit_price, double carpet_cost, double labor_cost, double   
installed_price, int percent_discount, double discount, double subtotal, double tax, 
double total);

#define LABOR_RATE 0.35
#define TAX_RATE 0.085

main.c

/*  This function calls three subfuctions to calculate the costs of installing a    
carpet and prints an invoice.  */

#include "my.h"

int main (void)

{
        int length;
        int width;
        int percent_discount;
        double unit_price;
        int area;
        double carpet_cost;
        double labor_cost;
        double installed_price;
        double discount;
        double subtotal;
        double tax;
        double total;

Read_Data(&length, &width, &percent_discount, &unit_price);

Calc_Values(length, width, percent_discount, unit_price, &area, &carpet_cost,  
&labor_cost,&installed_price, &discount, &subtotal, &tax, &total);

Print(length, width, area, unit_price, carpet_cost, labor_cost,
installed_price, percent_discount, discount, subtotal, tax, total);

return 0;
}

Read_Data.c

/*This function asks the user for the length and width of a room to be carpeted, the  
percent discount and the unit price of the carpet. */

#include "my.h"

void Read_Data (int* length, int* width, int* percent_discount, double* unit_price)

{
printf("What is the length, in feet, of the room?\n");
scanf("%d", length);

printf("What is the width, in feet, of the room?\n"); 
scanf("%d", width);

printf("What is the percent discount?\n");
scanf("%d", percent_discount);

printf("What is the unit price of the carpet?\n");
scanf("%lf", unit_price);

printf("\nThe length is %6d.\n", *length);   //These printf statements work properly.
printf("The width is %6d.\n", *width);
printf("The percent discount is %3d%.\n", *percent_discount);
printf("The unit price is $%7.2f.\n", *unit_price);

return;
}

Calc_Value.c

/*This function calls three subfuctions that calculate all required quantities.  */

#include "my.h"

void Calc_Values (int length, int width, int percent_discount, double unit_price, 
int* area, double* carpet_cost, double* labor_cost, double* installed_price, double*  
discount, double* subtotal, double* tax, double* total)

{

printf("\nUnit Price:  %7.2f.\n", unit_price);  //This printf statement works properly.

Install_Price (length, width, unit_price, area, carpet_cost, labor_cost, 
installed_price);

Subtotal (percent_discount, *installed_price, discount, subtotal);

Total (*subtotal, tax, total);

return;
}

Install_Price.c (repeating for user ease)

/*This function calculates the cost of the carpet and the labor cost in order to    
calculate the installed price.*/

#include "my.h"

void Install_Price (int length, int width, int unit_price, int* area, 
double* carpet_cost, double* labor_cost, double* installed_price)

{

printf("\nThe unit price is %7.2f.\n", *unit_price);  //THIS DOES NOT WORK

*area = length * width;
*carpet_cost = (*area) * unit_price;

printf("The carpet cost is %7d x %7.2f = %7.2f.\n", *area, unit_price, 
*carpet_cost);  //THIS DOES NOT WORK

*labor_cost = (*area) * LABOR_RATE;
*installed_price = (*carpet_cost) + (*labor_cost);

return;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T17:23:18+00:00Added an answer on May 25, 2026 at 5:23 pm

    Your issue is that in the Install_Price function declaration unit_price is declared an int, but in all other function definitions it is declared a double or *double. C is automatically casting the double to an int when you pass that value to Install_Price. The issue is with these two lines of code in Install_price:

    printf("\nThe unit price is %7.2f.\n", *unit_price);
    

    and

    printf("The carpet cost is %7d x %7.2f = %7.2f.\n", *area, 
           unit_price, *carpet_cost);
    

    You are using %f to print the unit price, which has been cast to an int.

    Changing the definition of Install_Price to

    void Install_Price (int length, int width, double unit_price, int* area, 
    double* carpet_cost, double* labor_cost, double* installed_price)
    

    Should solve one of your problems.

    The other issue is also in this line:

    printf("\nThe unit price is %7.2f.\n", *unit_price);
    

    unit_price should not be dereferenced in this line. Change this to:

    printf("\nThe unit price is %7.2f.\n", unit_price);
    

    To fix that issue.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I have just tried to save a simple *.rtf file with some websites and
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have some data like this: 1 2 3 4 5 9 2 6
I have a jquery bug and I've been looking for hours now, I can't
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.