StRiNg Question y'all!

The Problem:

You’re working for a lumber company, and your employer would like a program that calculates the cost of lumber for an order. The company sells pine, fir, cedar, maple, and oak lumber. Lumber is priced by board feet. One board foot equals one square foot, one inch thick. The price per board foot is given in the following table:
Pine 0.89
Fir 1.09
Cedar 2.26
Maple 4.50
Oak 3.10
The lumber is sold in different dimensions (specified in inches of width and height, and feet of length) that need to be converted to board feet. For example, a 2 x 4 x 8 piece is 2 inches wide, 4 inches high and 8 feet long, and equivalent to 5.333 board feet. An entry from the user will be in the form of a letter and four integer numbers. The integers are the number of pieces, width, height, and length. The letter will be one of P, F, C, M, O (corresponding to the five kind of wood) or T, meaning total. When the letter T, there are no integers following it on the line. The program should print out the price for each entry, and print the total after T is entered.
Develop the program using functional decomposition, and use proper style and documentation in your code. Your program should make appropriate use of value-returning functions in solving this problem. Be sure that the user prompts are clear, and that the output is labeled appropriately.


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
#include<iostream>
#include<string>
using namespace std;

double calcCost(int amntPieces, int width, int length, 
				   int height, char woodType);

int main()
{
	int amntPieces, width, length, height;
	double total = 0.0, cost;
	char woodType;

	do
	{
		cout<<"Enter item:";
		cin>>woodType;
		if(woodType=='T')
		{
			cout<<"Total cost: $"<<total<<endl;
			break;
		}
		cin>>amntPieces;
		cin>>width;
		cin>>length;
		cin>>height;

	cost=calcCost (amntPieces, width,length,height,woodType);
		cout<<", Cost: $"<<cost<<endl;
		total+=cost;
	
	}while(woodType!='T');

	system("pause");
	}
	double calcCost(int amntPieces, int width, int length, int height, char woodType)

	{
		double cost;
		string name;
		cost= (length * width *height)/12.0;
		cost= amntPieces * cost;
		if (woodType=='P')
		{
			cost=cost*0.89;
			name="Pine";
		}
		else if (woodType=='F')
		{
			cost=cost*1.09;
			name="Fir";
		}
		else if(woodType=='C')
		{
			cost=cost*2.26;
			name="Cedar";
		}
		else if (woodType=='M')
		{
			cost=cost*4.50;
			name="Maple";
		}
		else if (woodType=='O')
		{ 
			cost=cost*3.10;
			name="Oak";
		}
		cout<<amntPieces<<" "
			<<width<<"x"<<length<<"x"<<height<<name;
			return cost;
		}
	
		   
Last edited on
On line 46, you used a single quote (') instead of a double quote (").
On line 46, you used a single quote (') instead of a double quote (").


I noticed that @OP ninja edited his post and change what you said without saying a thing, I thought you were blind when I looked at line 46 and it was perfectly fine, Naughty @OP...

Edit: Change it to int main.

Edit 2: Dont expect me to read that wall of text assignment, Im too lazy for that.
Give us more information. Where does it go wrong, does it not compile? What errors do you get? Does it compile? Then whats the problem, not the right output? etc
Last edited on
caught it, but it still will not run. changed a couple more things, i think my problem is in here:
1
2
3
4
5
6
7
8
[code]double lumberPrice(int amntPieces, int width, int length, 
				   int height, char woodType);

int main()
{
	int amntPieces, width, length, height;
	double total = 0.0, cost;
	char woodType;


[/code]
Last edited on
All I see is the prototype function of lumberPrice. No initialization of the actual function. Are you leaving that part of the code out?

Edit: Just realized that the function "calcCost" has the same parameters as the function prototype named lumberPrice. So that's probably your problem.
Last edited on
Theres lots of problem in your code.

The prototype is called

1
2
double lumberPrice(int amntPieces, int width, int length, 
				   int height, char woodType);


But the actual function is called
double calcCost(i So whats up with that?

this is where it is messed up.

/tmp/ccBP6DGo.o: In function `main':
:(.text.startup+0xc9): undefined reference to `lumberPrice(int, int, int, int, char)'
collect2: error: ld returned 1 exit status
justhappy wrote:
this is where it is messed up.

/tmp/ccBP6DGo.o: In function `main':
:(.text.startup+0xc9): undefined reference to `lumberPrice(int, int, int, int, char)'
collect2: error: ld returned 1 exit status


I suggest changing the function name on line 36 from calcPrice to lumberPrice. If you don't want to do that, then change the prototype name and everywhere else that uses lumberPrice to fix your problem.
i am new to this... how do i get the string function to display correctly?
1
2
3
4
5
6
7
8
9
double cost;
		string name;
		cost= (length * width *height)/12.0;
		cost= amntPieces * cost;
		if (woodType=='P')
		{
			cost=cost*0.89;
			name="Pine";
		}


my string designation is not correct. when the code runs, the word "pine" or any of the other
wood types do not display at all...
this is my last question for this problem.
my string designation is not correct. when the code runs, the word "pine" or any of the other
wood types do not display at all...
this is my last question for this problem.


There is nothing wrong with the code. Please elaborate.
When the program is running, it is suppose to look something like this...

Enter item: P 10 2 4 8
10 2x4x8 Pine, cost: $47.47
Enter item: M 1 1 12 8
1 1x12x8 Maple, cost: $36.00
Enter item: T
Total cost:$83.47


the actual names of the trees do not run....

UPDATE: never mind, it was because I didnt capitolize my letter input
Thank you for the help!
Last edited on
Topic archived. No new replies allowed.