Problem compiling...no idea??

No idea whats going on with this one really...any advice?
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
#include <iostream>
#include <string>
#include <iomanip>

using namespace std;

float bf(int, int , int ); 
// Function Prototype 
int main () { 
	// Declaring variables 
	 
	string lumbertype; 
	int quantity; 
	int width; 
	int height; 
	int length;
	char lType;
	float ltotal; 
	float boaFeet; 
	float lcost = 0;
	float total = 0;

	cout << fixed << setprecision(2);

	cout << "Please enter your order by type of wood, quantity, width, height, and length. " 
		<< "See example: P 10 2 4 8 "<< endl <<"All calculations must be correctly formatted" 
		<< endl << endl; 

	cout << "By entering T in the order line, total cost of all orders will be displayed." << endl
		<< "Enter your order: ";

	cin >> lType;
	if(toupper(lType) == 'T')
		return 0;

	cin >> quantity; 
	cin >> width; 
	cin >> height;
	cin >> length; 
	 

	while (!(toupper(lType) == 'T')) { 
		if (toupper (lType) == 'F') { 
			lcost = 1.09; lumbertype = "Fir";
		} 
		else if (toupper (lType) == 'P') {
			lcost = .89; lumbertype = "Pine";
		} 
		else if (toupper (lType) == 'C') { 
			lcost = 2.26;
		lumbertype = "Cedar";
		}
		else if (toupper (lType) == 'M') {
			lcost = 4.50; 
			lumbertype = "Maple";
		} 
		else if ( toupper(lType) == 'O') {
			lcost = 3.10; 
			lumbertype = "Oak";
		}
		else { 
			cout << lType << " " << "is not a lumber type" << endl;
			cout << "Please enter a valid lumber type with order." << endl;
			cin.clear();
		} 
		
		boaFeet = bf(width, height, length);
		total += boaFeet * lcost * quantity;
		//1 1x12x8 Maple, cost: $36.00 

		
		cout << quantity << " " << length << "x" << width << "x" << height << " " << lumbertype << ", cost: $" << boaFeet * lcost * quantity << endl;
		
		cout << "Enter your order: ";
		cin >> lType;
		
		if (toupper(lType) == 'T') {
			cout << "Total cost: $" << total << endl;
		}
		else {
			cin >> quantity;
			cin >> width;
			cin >> length;
			cin >> height;
		}
	}
	
	system ("pause");
	return 0;
} 

float bf ( int width, int height, int length) {
	float squareFeet;
	float boardfeet;
	squareFeet = (length  * width) / 12.0;
	boardfeet = squareFeet * height;
	return boardfeet;
} 

What error messages are you getting?
Warnings pop up during compile. Compile succeeds but won't execute at all
warning C4305: '=' : truncation from 'double' to 'float' <-- shows up 4 times
warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
I don't get why your function 'bf' is of type float. All calculations involved are of type int, so when you return it you're just returning a float that will never have anything past the decimal point; basically an int.
Last edited on
well I'm fairly new to all of this...Wouldnt "bf" need be float? need more clarification this thing is causing some late night headaches
function bf should return a float since on line 95 you divide by 12.0.
This will most likely give you a float.
Try putting an F after a number to declare it as a float instead of double, like this:

squareFeet = (length * width) / 12.0F;

aside from that, warnings shouldn't keep your program from executing. This code should work, with or without warnings.
Is this the "way of choice" for this type of problem? Only way I knew but it seems like there could possibly be an easy button on this one?
function bf should return a float since on line 95 you divide by 12.0.

My point exactly. 12.0 may aswell be an integer as it is '.0'.
warnings that output when compiled...What is going on here it repeats for lines: 44, 47,50, 54, 58
warning C4305: '=' : truncation from 'double' to 'float'
Take for example Line 44:
float lcost = 1.09
because when you write a value literal like 1.09 in a program it is a double.
a double has more decimal places than a float so you will loose precision if you force it into a float.

You should do it like this:
float lcost = 1.09f Notice the f at the end of the number so signify float.
or double lcost.
Topic archived. No new replies allowed.