GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 28-Mar-2004, 21:01
soulfly soulfly is offline
New Member
 
Join Date: Mar 2004
Posts: 8
soulfly is on a distinguished road
Question

Can somebody look at this and point out any errors to me


It is compiling but I"m having linking errors.

inking...
4th group project.obj : error LNK2001: unresolved external symbol "void __cdecl printResultcharges(float *,float *,float *,float *,float *,float *)" (?printResultcharges@@YAXPAM00000@Z)
4th group project.obj : error LNK2001: unresolved external symbol "void __cdecl printResultmeasurements(int *,int *,int *)" (?printResultmeasurements@@YAXPAH00@Z)
4th group project.obj : error LNK2001: unresolved external symbol "void __cdecl calculate(int *,int *,int *,float *,float *,int *,float *,float *,float *,float *,float *,float *)" (?calculate@@YAXPAH00PAM10111111@Z)
4th group project.obj : error LNK2001: unresolved external symbol "void __cdecl getData(int *,int *,int *,float *)" (?getData@@YAXPAH00PAM@Z)
4th group project.obj : error LNK2001: unresolved external symbol "int __cdecl calcTotal(float *,float *,float *)" (?calcTotal@@YAHPAM00@Z)
4th group project.obj : error LNK2001: unresolved external symbol "int __cdecl calcSubtotal(float *,int *)" (?calcSubtotal@@YAHPAMPAH@Z)
4th group project.obj : error LNK2001: unresolved external symbol "int __cdecl calcInstall(float *,float *,float *)" (?calcInstall@@YAHPAM00@Z)
Debug/4th group project.exe : fatal error LNK1120: 7 unresolved externals
Error executing link.exe.

4th group project.exe - 8 error(s), 0 warning(s)



CPP / C++ / C Code:
#include <stdio.h>
#define TAX_RATE 8.5
#define LABOR_CHARGE 0.35


/* prototype declarations */

void getData (int *length,int *width, int *customer_discount, float *cost_of_carpet_per_sq_foot);
void calculate (int *length,int *width,int *area,float *cost_of_carpet_per_sq_foot,float *cost_of_carpet_per_room,int *customer_discount,float *installed_price,float *cost_of_labor,float *discount_price,float *sub_total,float *tax,float *total);
int calcInstall (float *cost_of_carpet_per_sq_foot,float *cost_of_labor,float *installed_price);
int calcSubtotal (float *installed_price, int *customer_discount);
int calcTotal (float *subtotal, float *tax, float *total);
void printResultmeasurements (int *length, int *width, int *area);
void printResultcharges (float *cost_of_carpet_per_sq_foot,float *cost_of_carpet_per_room,float *discount_price,float *sub_total,float *tax,float *total);

int main (void)

{
    int length;
	int width;
	int area;
	int customer_discount;
	float cost_of_carpet_per_sq_foot;
	float cost_of_carpet_per_room;
	float cost_of_labor;
	float installed_price;
	float discount_price;
	float sub_total;
	float tax;
	float total;	


	
	




	getData(&length,&width,&customer_discount,&cost_of_carpet_per_sq_foot);
	calculate(&length,&width,&area,&cost_of_carpet_per_sq_foot,&cost_of_carpet_per_room,&customer_discount,&cost_of_labor,&installed_price,&discount_price,&sub_total,&tax,&total);
    printResultmeasurements(&length,&width,&area);
	printResultcharges(&cost_of_carpet_per_sq_foot,&cost_of_carpet_per_room,&discount_price,&sub_total,&tax,&total);
	

    

	return 0;
}










void getData (int *length,int *width,int *customer_discount,int *cost_of_carpet_per_sq_foot)

{
	


	printf(" Length of room (feet) ? \n");
	scanf("%d", &length);
	printf(" Width of room (feet) ? \n");
	scanf("%d", &width);
	printf(" Customer discount (percent) ?\n ");
	scanf("%d",&customer_discount);
	printf(" Cost per square foot (xxx.xx) ? \n");
	scanf("%d",&cost_of_carpet_per_sq_foot);

	return;

}













void calculate (int &length,int &width,int &area,float &cost_of_carpet_per_sq_foot,float &cost_of_carpet_per_room,float &cost_of_labor,float &installed_price,int &customer_discount,float &discount_price,float &sub_total,float &tax,float &total)

	

{
    area = length * width;
	discount_price = cost_of_carpet_per_room - (float) customer_discount;
	tax = TAX_RATE * sub_total;
    cost_of_labor = LABOR_CHARGE * area;
	calcInstall (&cost_of_carpet_per_sq_foot,&cost_of_labor,&installed_price);
	calcSubtotal (&installed_price, &customer_discount);
	calcTotal (&sub_total,&tax,&total);

	return;

}













int calcInstall (float &cost_of_carpet_per_sq_foot,float &cost_of_labor,float &cost_of_carpet_per_room,int &area,float &installed_price)

{

	

    cost_of_labor = LABOR_CHARGE  *  (float) area;
	installed_price = cost_of_labor * cost_of_carpet_per_room;

	return (installed_price);

}














int calcSubtotal (int &installed_price, int &customer_discount,float &sub_total)



	

{
	

	sub_total = installed_price - customer_discount; 

	return (sub_total);

}












int calcTotal (int &subtotal, int &tax, int &total)


	
{
	total = subtotal * tax;

	return (total);

}
















void printResultmeasurements (int &length, int &width, int &area)

	
{
	printf ("          MEASUREMENT\n\n");
	printf ("Length                      %d ft\n\n",length);
	printf ("Width                       %d ft\n\n",width);
	printf ("Area                        %d square ft\n\n",area);


	return;

}















void printResultcharges (float &cost_of_labor,float &installed_price,int &cost_of_carpet_per_sq_foot,int &cost_of_carpet_per_room,int customer_discount,int &discount_price,int &subtotal,int &tax,int &total)

{

	printf ("           CHARGES\n\n");
	printf ("DESCRIPTION     COST/SQ.FT.     CHARGE/ROOM\n\n");
	printf ("-----------     -----------     -----------\n\n");
	printf ("Carpet             %6.2f             $%7.2f\n\n",cost_of_carpet_per_sq_foot,cost_of_carpet_per_room);
	printf ("Labor               0.35              %7.2f\n\n",cost_of_labor);
	printf ("                                -----------\n\n");
	printf ("INSTALLED PRICE                      $%7.2f\n\n",installed_price);
	printf ("Discount           %4.1f%%            %7.2f\n\n",customer_discount,discount_price);
	printf ("                                -----------\n\n");
	printf ("SUBTOTAL                             $%7.2f\n\n",subtotal);
	printf ("Tax                                   %7.2f\n\n",tax);
	printf ("TOTAL                                $%7.2f\n\n",total);


	return;

}


  #2  
Old 29-Mar-2004, 00:00
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,245
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all
unresolved external symbol

The specified symbol (variable, function, et al) has not been defined.

1) check your parameters to make sure the prototype, the function definition, and the parameters on the call match.

2) format your code bett than this. There's way too many blank lines and not enough or inconsistant indentation
__________________

Age is unimportant -- except in cheese
  #3  
Old 29-Mar-2004, 08:48
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,720
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold
I have extracted the function getData() for purposes of illustration.

Consider
CPP / C++ / C Code:
#include <stdio.h>

void getData (int *length, int *width, int *customer_discount, 
              float *cost_of_carpet_per_sq_foot);

int main (void)

{
  int length;
  int width;
  int area;
  int customer_discount;
  float cost_of_carpet_per_sq_foot;

  getData(&length, &width, &customer_discount, &cost_of_carpet_per_sq_foot);
  printf("\n\nFrom getData():\n");
  printf("  length                     =  %d feet\n", length);
  printf("  width                      =  %d feet\n", width);
  printf("  customer_discount          =  %d percent\n", customer_discount);
  printf("  cost_of_carpet_per_sq_foot = $%.2f\n", cost_of_carpet_per_sq_foot);

  return 0;
}

void getData (int *length,int *width,int *customer_discount,
              float *cost_of_carpet_per_sq_foot)

{
  printf(" Length of room (feet) ? ");
  scanf("%d", length);
  printf(" Width of room (feet)  ? ");
  scanf("%d", width);
  printf(" Customer discount (percent)   ? ");
  scanf("%d",customer_discount);
  printf(" Cost per square foot (xxx.xx) ? ");
  scanf("%f",cost_of_carpet_per_sq_foot);

  return;
}

Note that the function declaration is exactly the same as its prototype (same number of arguments, same type of arguments, in the same order).

OK, now look at the implementation of the function:

Now, for this function you have declared that length is a pointer to an int, so scanf() uses length as its argument.

Also, back in main(), for debug purposes, I suggest that you always print out the values that were changed in the function before you continue with calculations using the values

Does this get you started?

You can add the other functions, one at a time, and debug them as you go.
(Just a suggestion --- start with something that works and implement it incrementally.)

Dave
  #4  
Old 30-Mar-2004, 23:16
soulfly soulfly is offline
New Member
 
Join Date: Mar 2004
Posts: 8
soulfly is on a distinguished road

Here is my revised code but my calculations aren't working correctly


CPP / C++ / C Code:
#include <stdio.h>
#define TAX_RATE 8.5       
#define LABOR_CHARGE 0.35  


/**** prototype function  declarations ****/

void getData                 ( int   *length,
				               int   *width, 
				               int   *customer_discount, 
				               float *cost_of_carpet_per_sq_foot );
			 	
void calculate               ( int   *length,
				               int   *width,
				               int   *area,
				               float *cost_of_carpet_per_sq_foot,	
				               float *cost_of_carpet_per_room,
				               int   *customer_discount,
				               float *installed_price,
				               float *cost_of_labor,
				               float *discount_price,
				               float *sub_total,
				               float *tax,
				               float *total );
			 	
void calcInstall              (float *cost_of_carpet_per_sq_foot,
				               float *cost_of_labor,	
				               float *cost_of_carpet_per_room,
				               int   *area,
				               float *installed_price );
             
void calcSubtotal            ( float *installed_price, 
				               int   *customer_discount,
							   float *sub_total );

void calcTotal               ( float *sub_total, 
				               float *tax, 
				               float *total );

void printResultmeasurements ( int   *width,
							   int   *length,
                               int   *area );
                               
void printResultcharges      ( float *cost_of_labor,
                               float *installed_price,
							   float *cost_of_carpet_per_sq_foot,
							   float *cost_of_carpet_per_room,
                               int   *customer_discount,
							   float *discount_price,
							   float *sub_total,
							   float *tax,
							   float *total );
							   
							   
 /****begin main****/


int main (void)

{
 /****definitions****/

    int length;
	int width;
	int area;
	int customer_discount;
	float cost_of_carpet_per_sq_foot;
	float cost_of_carpet_per_room;
	float cost_of_labor;
	float installed_price;
	float discount_price;
	float sub_total;
	float tax;
	float total;	

/*****Fucnction Calls*****/

	getData(&length,
		    &width,
		    &customer_discount,
		    &cost_of_carpet_per_sq_foot );

	calculate(&length,
		      &width,
		      &area,
		      &cost_of_carpet_per_sq_foot,
		      &cost_of_carpet_per_room,
		      &customer_discount,
		      &installed_price,
		      &cost_of_labor,
		      &discount_price,
		      &sub_total,
	  	      &tax,
		      &total );

    printResultmeasurements(&length,
		                    &width,
							&area );

	printResultcharges(&cost_of_labor,
		               &installed_price,
                       &cost_of_carpet_per_sq_foot,
		               &cost_of_carpet_per_room,
					   &customer_discount,
					   &discount_price,
					   &sub_total,
					   &tax,
					   &total );
	

   	return 0;
} /*** end main ****/


/**** begin getData function ***/

void getData (int *length,
			  int *width,
			  int *customer_discount,
			  float *cost_of_carpet_per_sq_foot )

{
	


	printf(" Length of room (feet) ? \n");
	scanf("%d", length);
	printf(" Width of room (feet) ? \n");
	scanf("%d", width);
	printf(" Customer discount (percent) ?\n ");
	scanf("%d", customer_discount);
	printf(" Cost per square foot (xxx.xx) ? \n");
	scanf("%f", cost_of_carpet_per_sq_foot);

	return;

} /****** end getData Function ******/


/***begin calculate function to call other calculate subfunctions ****/ 

void calculate (int *length,
				int *width,
				int *area,
				float *cost_of_carpet_per_sq_foot,
				float *cost_of_carpet_per_room,
				int   *customer_discount,
				float *installed_price,
				float *cost_of_labor,
				float *discount_price,
				float *sub_total,
				float *tax,
				float *total )

	

{ /**** Statements to calculate area, discount price, tax, cost of labor ***/

    *area = *length * *width;
	*discount_price = *cost_of_carpet_per_room - *customer_discount;
	*tax = TAX_RATE * *sub_total;
    *cost_of_labor = LABOR_CHARGE * *area;      /* end statements*/
   
 /****Calculate subfunction calls begin here ****/
    
	calcInstall  (              cost_of_carpet_per_sq_foot,
				                cost_of_labor,	
				                cost_of_carpet_per_room,
				                area,
								installed_price);

	calcSubtotal (              installed_price, 
				                customer_discount,
								sub_total);

	calcTotal    (   		    sub_total,
		                        total,
				                tax );  /**Calculate subfunctions calls end here**/

	return;

}       /**** end calculate function ****/


/**** Begin calcInstall subfunction ****/

void calcInstall (float *cost_of_carpet_per_sq_foot,
				 float  *cost_of_labor,	
				 float  *cost_of_carpet_per_room,
				 int    *area,
				 float  *installed_price )

{

	/***cost_of_carpet_per_room = *cost_of_carpet_per_sq_foot***/ 
	*cost_of_carpet_per_room = *cost_of_carpet_per_sq_foot * *area;
    *cost_of_labor = LABOR_CHARGE  *  *area;
	*installed_price = *cost_of_labor * *cost_of_carpet_per_room;

	return ;

} /**** End calcInstall subfunction****/




  /**** Begin calcSubtotal subfunction ****/
        
void calcSubtotal (float *installed_price, 
				   int *customer_discount,
				   float *sub_total)


{
	
      
        
	*sub_total = *installed_price - *customer_discount;  /* calculating subtotal*/ 

	return ;

}      /**** End calcSubtotal subfunction ****/




       /* Begin calcTotal subfunction*/
       
void calcTotal ( float *sub_total, 
			     float *tax, 
			     float *total )


	
{
	*total = *sub_total * *tax;

	return;

}  /* End calcTotal subfunction*/




     /* Begin Print function to print out measurements */
     
void printResultmeasurements ( int *length, 
							   int *width, 
							   int *area )

	
{
	printf ("          MEASUREMENT\n\n");
	printf ("Length                      %d ft\n\n",length);
	printf ("Width                       %d ft\n\n",width);
	printf ("Area                        %d square ft\n\n",area);


	return;

}    /* End print function to print out measurements */




     /* Begin print function to print out Charges*/
     
void printResultcharges ( float *cost_of_labor,
                          float *installed_price,
                          float *cost_of_carpet_per_sq_foot,
                          float *cost_of_carpet_per_room,
                          int   *customer_discount,
                          float *discount_price,
                          float *sub_total,
                          float *tax,
                          float *total )

{

	printf ("           CHARGES\n\n");
	printf ("DESCRIPTION     COST/SQ.FT.     CHARGE/ROOM\n\n");
	printf ("-----------     -----------     -----------\n\n");
	printf ("Carpet             %6.2f             $%7.2f\n\n",cost_of_carpet_per_sq_foot,cost_of_carpet_per_room);
	printf ("Labor               0.35              %7.2f\n\n",cost_of_labor);
	printf ("                                -----------\n\n");
	printf ("INSTALLED PRICE                      $%7.2f\n\n",installed_price);
	printf ("Discount           %4.1f%%            %7.2f\n\n",customer_discount,discount_price);
	printf ("                                -----------\n\n");
	printf ("SUBTOTAL                             $%7.2f\n\n",sub_total);
	printf ("Tax                                   %7.2f\n\n",tax);
	printf ("TOTAL                                $%7.2f\n\n",total);


	return;

}     /* end print charges function */
  #5  
Old 30-Mar-2004, 23:29
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,245
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all
Please ask a specific question with enough information that we understand the problem and post the code with the problem you are having. We don't usually need the entire program to search thru to find an ambuguously defined problem.

And take another look at your formatting. Your intenting is still inconsistant. Try not to use tabs but spaces.
__________________

Age is unimportant -- except in cheese
  #6  
Old 30-Mar-2004, 23:40
soulfly soulfly is offline
New Member
 
Join Date: Mar 2004
Posts: 8
soulfly is on a distinguished road
I'm sorry Walt but I'm trying and learning. This program compiles and runs but the output is just zero. Thanks for your help
  #7  
Old 31-Mar-2004, 08:31
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,720
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold
Quote:
Originally Posted by soulfly
I'm sorry Walt but I'm trying and learning. This program compiles and runs but the output is just zero. Thanks for your help


Here's a suggestion: Start with the getData(): In the main program, print out all values that were obtained from getData(). Try something like this:

CPP / C++ / C Code:
  getData(&length,
        &width,
        &customer_discount,
        &cost_of_carpet_per_sq_foot );
  printf("From getData(): length = %d, width = %d, customer_discount = %d, cost = %f\n",
          length, width, customer_discount, cost_of_carpet_per_sq_foot);

If this is not OK, put printf() statements inside the getData() function to see what's happening.

If getData() gives you good data, then go to the next function that you call from main(). That's calculate().

Go inside calculate() and printf() all values coming into the function. This makes sure that you are passing the correct data to the function.

Now, use printf() after each calculation to see if the results are what you expect.

Continue in this manner, inserting printf() as you go into each function, as you perform calculations, and as you leave each routine.

If this sounds tedious, too bad. I claim that it's still faster than posting an appeal for help and waiting for a helpful response.

I always like to say, "printf() is your friend."

Good Luck!!!

Dave
  #8  
Old 31-Mar-2004, 09:45
dsmith's Avatar
dsmith dsmith is offline
Senior Member
 
Join Date: Jan 2004
Location: Utah, USA
Posts: 1,351
dsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of light
Hi Soulfly. I think that some of your confusion is coming when you are passing pointers into your functions. The only reason that I would pass a pointer to a function is when I need to change the value of that parameter, but for just printing the value, there is no reason to pass a pointer. If you do pass a pointer however, make sure that you are indexing properly for your function.

For example, printf unlike scanf does not take the address of the variable, but the variable itself, so in your functions, you need to change your printfs as follows:
CPP / C++ / C Code:
 
     /* Begin print function to print out Charges*/
     
void printResultcharges ( float *cost_of_labor,
                          float *installed_price,
                          float *cost_of_carpet_per_sq_foot,
                          float *cost_of_carpet_per_room,
                          int   *customer_discount,
                          float *discount_price,
                          float *sub_total,
                          float *tax,
                          float *total )

{

	printf ("           CHARGES\n\n");
	printf ("DESCRIPTION     COST/SQ.FT.     CHARGE/ROOM\n\n");
	printf ("-----------     -----------     -----------\n\n");
	printf ("Carpet             %6.2f             $%7.2f\n\n",*cost_of_carpet_per_sq_foot,*cost_of_carpet_per_room);
	printf ("Labor               0.35              %7.2f\n\n",*cost_of_labor);
	printf ("                                -----------\n\n");
	printf ("INSTALLED PRICE                      $%7.2f\n\n",*installed_price);
	printf ("Discount           %4.1f%%            %7.2f\n\n",*customer_discount,*discount_price);
	printf ("                                -----------\n\n");
	printf ("SUBTOTAL                             $%7.2f\n\n",*sub_total);
	printf ("Tax                                   %7.2f\n\n",*tax);
	printf ("TOTAL                                $%7.2f\n\n",*total);


	return;

}     /* end print charges function */

However, my recommendation would be to change the entire function to this:
CPP / C++ / C Code:
   
 /* Begin print function to print out Charges*/
     
void printResultcharges ( float cost_of_labor,
                          float installed_price,
                          float cost_of_carpet_per_sq_foot,
                          float cost_of_carpet_per_room,
                          int   customer_discount,
                          float discount_price,
                          float sub_total,
                          float tax,
                          float total )

{

	printf ("           CHARGES\n\n");
	printf ("DESCRIPTION     COST/SQ.FT.     CHARGE/ROOM\n\n");
	printf ("-----------     -----------     -----------\n\n");
	printf ("Carpet             %6.2f             $%7.2f\n\n",cost_of_carpet_per_sq_foot,cost_of_carpet_per_room);
	printf ("Labor               0.35              %7.2f\n\n",cost_of_labor);
	printf ("                                -----------\n\n");
	printf ("INSTALLED PRICE                      $%7.2f\n\n",installed_price);
	printf ("Discount           %4.1f%%            %7.2f\n\n",customer_discount,discount_price);
	printf ("                                -----------\n\n");
	printf ("SUBTOTAL                             $%7.2f\n\n",sub_total);
	printf ("Tax                                   %7.2f\n\n",tax);
	printf ("TOTAL                                $%7.2f\n\n",total);


	return;

}     /* end print charges function */

Also, while I am making recommendations, have you ever thought of throwing this into a structure? It sure would make passing it easier, IMHO.

Good luck,
d
 
 

Recent GIDBlogDeveloping GUIs with wxPython (Part 3) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 20:48.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.