Calculates the cost of lumber

Write your question here.
I’m new at this and we are studding Scope, Lifetime, and More on Functions the program should give the total for all the orders. Mine is not so if anyone can help I would be thankful.

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.
Last edited on
I change it up but still not working right.

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
#include <iostream>
#include <cmath> 
#include <iomanip>

using namespace std;



float bCalculation(char bType, int& bNumb, int& bWide, int& bHigh, int& bLong,float& tCost,float total);
void bTotal(char bType, float& total, float tCost);
int main()
{   
	char bType;
	int bNumb;
	int bWide = 0;
	int bHigh = 0;
	int bLong = 0;
	float tCost = 0;
	float total = 0;
	do
	{
		cout << "Enter item: ";
		cin >> bType>> bNumb >> bWide >> bHigh >> bLong;
		if(bType != 'T'||bType != 't')//I changed this up a bit//
		{
			
			while (bNumb <= 0 || bWide <= 0 || bHigh <= 0 || bLong <= 0)
			{
				cout <<"Incorrect Input, Plese enter type, number of Pieces, Width, Height,Length" << endl;
				cin >> bType >> bNumb >> bWide >> bHigh >> bLong;
				cout << endl;
			}

			total = total + bCalculation(bType,bNumb,bWide,bHigh,bLong,tCost,total); //here is where I assign it to total//

			switch(toupper(bType))
			{
			case 'P': cout << bNumb << " " << bWide << "x" << bHigh << "x" << bLong << " " <<
						  " Pine " <<  fixed << setprecision(2) << tCost << endl ;
				break;
			case 'F': cout << bNumb << " " << bWide << "x" << bHigh << "x" << bLong << " " <<
						  " Fir " <<  fixed << setprecision(2) << tCost << endl ;
				break;
			case 'C': cout << bNumb << " " << bWide << "x" << bHigh << "x" << bLong << " " <<
						  " Ceader " <<  fixed << setprecision(2) << tCost << endl ;
				break;
			case 'M' : cout << bNumb << " " << bWide << "x" << bHigh << "x" << bLong << " " <<
						   " Maple " <<  fixed << setprecision(2) << tCost << endl ;
				break;
			case 'O' : cout << bNumb << " " << bWide << "x" << bHigh << "x" << bLong << " " <<
						   " Oak " <<  fixed << setprecision(2) << tCost << endl ;
				break;
			case 'T': cout << "Total cost: "<< fixed << setprecision(2) << tCost << endl;
				break;
			default :cout << "Incorrect Input, Please use letter (P, F, C, M, O) for wood type,or T for total." <<endl;
			}
		

			cout << total << endl;		// here is where I call it to the screen//
		}


	}while(bNumb,bWide, bHigh, bLong );
	return 0;
}


float bCalculation(char bType, int& bNumb, int& bWide, int& bHigh, int& bLong,float& tCost,float total)
{

	float tMessure;
	float sCost;
	float bPrice = 0;

	if(toupper(bType) == 'P')
		bPrice = 0.89;
	if(toupper(bType) == 'F')
		bPrice = 1.09;
	if(toupper(bType) == 'C')
		bPrice = 2.26;
	if(toupper(bType) == 'M')
		bPrice = 4.50;
	if(toupper(bType) == 'O')
		bPrice = 3.10;

	tMessure = (bWide * bHigh * bLong);	
	sCost = (tMessure / 12)* bPrice;	
	tCost = sCost * bNumb;

	return tCost;
}
Last edited on
Can you use the code commands to format this?
Thank you this my first post here. This code gives me total after each input and I need the total when the input is T or t.
Last edited on
I would like to hear if anyone has some helpful ideas
Last edited on
closed account (D80DSL3A)
You should describe what's wrong in some detail. "not working right" is an inadequate problem description. What results do you expect from the program? What results are you getting? Do you have any idea where the problems are?
I am new at writing code this is my eighth program so I don't know where the problem is.
For example when I input P for pine 10 for bNumb and the dimensions 2 4 8
the cout is 10 2 x 4 8 Pine 47.47
then enter M 1 1 12 8
the cout is 1 1 x 12 x 8 Maple 36.00
that all works, put when I enter 'T' I do not get the total for both orders.
Last edited on
Topic archived. No new replies allowed.