Do while loop issue

For reference, here is my project statement:

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 × 4 × 8 piece is 2 inches wide, 4 inches high, and 8 feet long, and is 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 kinds of wood) or T, meaning total. When the letter is 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.

With that all being said, I've developed a program for it but am running into an issue with one of my do while loops. The program compiles fine with no errors and when I run it the program prompts for user input but even if it is an acceptable option it is giving the user my error message from the second do while loop continuously and I'm not really sure why.

Any thoughts would be appreciated.

Here is a link to my code:
http://codepad.org/38xlnTF3

use this

1
2
3
4
5
6
7
8
	     do
		{
		cout << "You have made an invalid selection. Please ready carefully and try again." << endl;
		cout << "Enter your type of wood (P for Pine, F for Fir, C for Cedar, M for Maple, or O for Oak): ";
		cin >> woodType;
		} while (!(woodType == 'P' || 'F' || 'C' || 'M' || 'O'));

Last edited on
Replaced the existing do loop with what you have above and ran into the same problem as before.

EDIT: I lied actually. After declaring char woodType again within the do while loop it will work for capital P but anything else, even F, C, M, or O will throw the same error.

1
2
3
4
5
6
7
do
		{
			char woodType;
			cout << "You have made an invalid selection. Please ready carefully and try again." << endl;
			cout << "Enter your type of wood (P for Pine, F for Fir, C for Cedar, M for Maple, or O for Oak): ";
			cin >> woodType;
		} while (!(woodType == 'P' || 'F' || 'C' || 'M' || 'O'));
Last edited on
its working fine i just check it
check your here www.cpp.sh
woodType == needs to be part of each different condition the code checks.

woodType == 'P' || woodType == 'F' || woodType == 'C' || woodType == 'M' || woodType == 'O'
@bird1234 I did and still received the same issue.

http://i.imgur.com/8Jhgm89.png
Last edited on
@wildblue also tried that out and am running into same issue except now it doesn't even work for P it throws the error for every option
With the do while loop, the error message gets spit out even if a valid entry has been made. With a plain while loop, the error message/re-entry process can be skipped if a valid entry is made.

1
2
3
4
5
6
while(woodType != 'P' && woodType != 'F' && woodType != 'C' && woodType != 'M' && woodType != 'O')
{
	cout << "You have made an invalid selection. Please read carefully and try again." << endl;
	cout << "Enter your type of wood (P for Pine, F for Fir, C for Cedar, M for Maple, or O for Oak): ";
	cin >> woodType;
}
Last edited on
Topic archived. No new replies allowed.