Calculation

How do I do the calculation for "width * height * length"

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

using namespace std;

int main() {

	//price of wood per square foot
	//dimension of wood
	//inch X inch X foot
	//convert to board feet
	//integers = number of pieces, width, height, and length

	const double pine = 0.89;
	const double fir = 1.09;
	const double cedar = 2.26;
	const double maple = 4.50;
	const double oak = 3.10;
	double currentCost = 0;
	double totalCost = 0;
	double width = 0;
	double height = 0;
	double length = 0;


		cout << "Enter item: ";
	string item;
	cin >> item;
	string letter;
	int feet = width * height * length;
	currentCost = feet / 12.0;

	// Find the first space in the string
	int pos = item.find(" ");
	letter = item.substr(0, pos);
	item.erase(0, pos + 1);

	// Find the second space in the string
	pos = item.find(" ");
	string numberOfItems = item.substr(0, pos);
	item.erase(0, pos + 1);

	//Find the third space in the string
	pos = item.find(" ");
	string width = item.substr(0, pos);
	item.erase(0, pos + 1);

	//Find the fourth space in the string
	pos = item.find(" ");
	string height = item.substr(0, pos);
	item.erase(0, pos + 1);

	//Find the fifth space in the string
	pos = item.find(" ");
	string length = item.substr(0, pos);
	item.erase(0, pos + 1);

		// Declare variables to hold the current cost of current item, total cost,
		// Prompt user for input "Enter item: " until user enters T

}
Ok, clearly this is new to you. That's not a problem.

First, since you've declared doubles already for width, height and length, you should declare "feet" (which I assume is cubic feet) as a double, not an integer. Initialize it to 0.0 with

double feet = 0.0;

Don't bother with the calculation you have in that line where you declare feet, they haven't been supplied by the user yet.

Next, things otherwise look ok for asking for the item. However, it is way too early to use feet or calculate currentCost. You must ask for the width, height and length first.

Here's where you need to review what cin does. Let's say someone enters:

A 4 3.5 4.5 6.5

Which would be letter a, 4 items, 3.5 by 4.5 by 6.5 feet (I assume the units are feet).

That seems uncomfortable as a user interface, doesn't it? It would be smoother to ask for each parameter and then take that input.

Besides, even with a string the space separates these from each other, so that item string is only going to have "A" in it from my sample input string.

So, if your first parameter is the letter, ask for a letter with something like

1
2
cout << "Enter letter: ";
cin >> letter;


In this case, letter may be a string.

Then, ask for quantity:

1
2
3
int numberOfItems{0};
cout << "Enter quantity: ";
cin >> numberOfItems;


It shouldn't be a string.

Do the same for the rest of the parameters, after which you'll be able to calculate feet AFTER these parameters have been requested.

Try that and post your efforts.
Topic archived. No new replies allowed.