Function Problem, what is wrong with this code?

anyone can fix the error in this code?
please try to run it to your compiler.
im using Quincy 2005 compiler.

id get a few errors and i'm confused on how to solve it.
thanks
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#include <stdio.h>

float inputData(float length, float width, float discount, float price);
float calcInstall (float area, float price, float laborCost);
float calcSubTotal(float discount, float iPrice);
float caclTotal(float subTotal, float tax);
float calculate (float area, float discount, float price, float laborCost, float iPrice, float subTotal, float tax);
float printMeasurements(float length, float width);
float printtCharges  (float area, float discount, float price, float subTotal, float total, float tax, float laborCost, float iPrice);
float printtResults(float length, float width, float discount, float price);



int main()

{
	float length, width, area;
	float price, discount, iPrice, subTotal, total;
	const  laborCost=0.09;
	const  tax=0.05;

	inputData(length, width, discount, price);
	iPrice=calcInstall(area, price, laborCost);
	subTotal=calcSubTotal(discount, iPrice);
	total=calcTotal(subTotal, tax);
	calculate (area, discount, price, laborCost, iPrice, subTotal, tax);
	printMeasurements(length, width);
	printCharges (area, discount, price, subTotal, total, tax, laborCost, iPrice);
	printResults(length, width, discount, price, area );
	
	return 0;
	
}

float inputData(float length, float width, float discount, float price)

{
	printf("\nLength of Room (in feet) >");
	scanf("%d", &length);
	
	printf("\nWidth of Room (in feet) >");
	scanf("%d", &width);
	
	printf("\nCustomers discount (in percent) >");
	scanf("%f", &discount);
	
	printf("\nCost per square foot (000.00) >");
	scanf("%f", &price);  

}

float calcInstall (float area, float price, float laborCost)
{
	return (price + laborCost) * area;
}

float calcSubTotal(float discount, float iPrice)
{
	return iPrice - discount * iPrice * 0.01;
}

float caclTotal(float subTotal, float tax)
{
	return subTotal + ( subTotal * tax );
}


float calculate (float area, float discount, float price, float laborCost, float iPrice, float subTotal, float tax)
{
	calcInstall(area, price, laborCost);
	calcSubTotal(discount, iPrice);
	caclTotal(subTotal, tax);
}

float printMeasurements(float length, float width)
{
	printf("\n\n\t\t\t\tMeasurement\n");
	printf("\n\t\t\tLength %10d feet", length);
	printf("\n\t\t\tWidth  %10d feet", width);
	printf("\n\t\t\tArea   %10d feet", length * width);
}

float printCharges (float area, float discount, float price, float subTotal, float total, float tax, float laborCost, float iPrice)
{
	
	calculate (area, discount, price, laborCost, iPrice, subTotal, tax)
	printf("\n\n\t\t\t\tCharges\n");
	printf("\n\tDESCRPTION\tCOST/SQ.FT.\tCHARGE/ROOM");
	printf("\n\t--------------------------------------------");
	printf("\n\tCarpet %15.2f %14.2f $", price, price * area);
	printf("\n\tLabor  %15.2f %14.2f $", laborCost, laborCost * area);
	printf("\n\t\t\t\t---------------");
	
	printf("\n\tInstalled Price %21.2f $", iPrice);
	printf("\n\tDiscount %13.2f %14.2f $", discount, discount * iPrice * 0.01);
	printf("\n\t\t\t\t---------------");
	
	printf("\n\tSub Total %27.2f $", subTotal);
	printf("\n\tTax %33.2f $", subTotal * tax);
	printf("\n\t\t\t\t---------------");
	
	printf("\n\tTotal %31.2f $\n\n\t", total);
}

void printResults(float length, float width, float discount, float price)
{
	float area= length * width;
	printMeasurements(length, width);
	printCharges(area, discount, price);
}


Firstly, printCharges and printResults aren't known in the main function (you have printtCharges and printtResults, though). If you post the errors you're getting, will try and help you with the rest of them.
here is a print screen of the error http://62.0.5.134/imgur.com/Um1Sf.jpg

please? how do i solve this error. thank you.
okay, so i just noticed that i misspelled those function.
my program will run now tho i'd get wrong results like this

http://62.0.5.133/imgur.com/CAXPL.jpg

Ok, your links don't work for me.

But... I think you need to read up on the use of references. At the moment all your earlier functions return nothing, and work on local copies of variables. You want to pass and use references (denoted by &) so that the functions act on the *same* variable that is passed to them.

http://www.cplusplus.com/doc/tutorial/functions2/

That page explains how to use references.
Last edited on
Compare lines 10 and 105; you declared function to be returning floats but instead you used void in real function.
Why you used floats as return type on functions calculate(), printMeasurements(), printCharges() and inputData() since they does not return anything? Use void instead.

If i make similar program i would be using either references or pointers in function parameters ;)
Topic archived. No new replies allowed.