Completed Programming Assignment Check

I just completed an assignment and was wondering if you guys could look it over. Everything looks okay to me, except for where it calculates the price for the total paint cost. I know there should be some sort of conversion, but I'm not sure if I'm correct.

Here is the problem:

Amanda and Tyler opened a business that specializes in shipping liquids, such as milk, juice, and water, in cylindrical containers. The shipping charges depend on the amount of liquid in the container. (For simplicity, you may assume that the container is filled to the top.) They also provide the option to pain the outside of the container for a reasonable amount. Write a program that does the following:

a. Prompts the user to input the dimensions (in feet) of the container (radius of the base and the height).
b. Prompts the user to input the shipping cost per liter.
c. Prompts the user to input the paint cost per square foot. (Assume that the entire container including the top and bottom needs to be painted.)
d. Separately outputs the shipping cost and the cost of painting.

Your program must use the class cylinderType to store the radius of the base and the height of the container. (Note that 1 cubic feet = 28.32 liters or 1 liter = 0.353146667 cubic feet.)


Here is my code:

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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#include <iostream>

using namespace std;

class cylinderType
{
	public:
		void setRadius(double r);
		double getRadius();
		void setHeight(double h);
		double getHeight();
		double volume();
		double area();
		cylinderType(double r, double h);
		cylinderType();
		
	private:
		double radius;
		double height;
};
	


void cylinderType::setRadius(double r)
{
	if (r >= 0)
		radius = r;
	else
		radius = 0;
}
	
double cylinderType::getRadius()
{
	return radius;
}

void cylinderType::setHeight(double h)
{
	if (h >= 0)
		height = h;
	else
		height = 0;
}
	
double cylinderType::getHeight()
{
	return height;
}

double cylinderType::volume()	//Calculates the volume of the cylinder
{
	return 3.14*(radius*radius)*height;
}

double cylinderType::area()		//Calculates the area of the cylinder
{
	return (2*3.14*radius*height) + (2*3.14*(radius*radius));
}

cylinderType::cylinderType(double r, double h)
{
	setRadius(r);
	setHeight(h);
}

cylinderType::cylinderType()
{
	radius = 0;
	height = 0;
}


	
int main()
{
	double radius;
	double height;
	double shipCost;
	double paintCost;
	double paintTotal;
	double total;
	char answer;
	
	cylinderType program;
	
	//Prompts the user to input the dimensions (in feet) of the container (radius of the base and the height)
	cout << "This is Amanda & Tyler's Cylinder Painting and Shipping services." << endl << endl;
	cout << "Please enter the dimensions of the container (radius and height)." << endl;
	cout << "Radius (in feet): ";
	cin >> radius;
	cout << endl;
	cout << "Height (in feet): ";
	cin >> height;
	cout << endl << endl;
	
	//Sets radius and height from the input values
	program.setRadius(radius);
	program.setHeight(height);
	
	//Prompts the user to input the shipping cost per liter
	cout << "Please enter the shipping cost per liter: $";
	cin >> shipCost;
	cout << endl;
	total = shipCost * program.volume() * 28.32;	//Includes conversion from liters to cubic feet
	cout << "Based on the container dimensions and shipping cost, your total comes to $" << total << endl;
	
	//Provides the option to paint the outside of the container and outputs the cost of painting separately
	while (answer != 'Y' || answer != 'N')
	{
	cout << "Would you like the container to be painted?" << endl;
	cout << "Enter Y for Yes or N for No: ";
	cin >> answer;
	cout << endl;
	if (answer == 'Y' || answer == 'y')
	{
		cout << "Please enter the paint cost per square foot: ";
		cin >> paintCost;
		cout << endl;
		paintTotal = paintCost * program.area();
		total = (shipCost * program.volume()) + (paintCost * program.area());
		cout << "The cost of painting the container comes to $" << paintTotal << endl;
		cout << "Your new total, including shipping and painting cost, is $" << total << endl << endl;
		cout << "Thank you for choosing Amanda & Tyler's Cylinder Painting and Shipping services." << endl;
	}
	else if (answer == 'N' || answer == 'n')
	{
		cout << "Your final total is $" << total << endl << endl;
		cout << "Thank you for choosing Amanda & Tyler's Cylinder Painting and Shipping services." << endl;
	}
	break;
	}
	
	return 0;
}
Just off the top of my head...

1. The line:
while (answer != 'Y' || answer != 'N')
will always be true. Answer will never be both. You may want to change that line to:
while (answer != 'Y' && answer != 'N')

by the way, it's better form to initiate the variable 'answer' to a defined value. That will prevent it from accidently ever being 'Y' or 'N' initially.

2. I may be wrong, but it looks like the 2nd to the last line: break; , will always occur, no matter what is entered - to continue or not. Try it and loop during the test to see if your 'while' loop works.

hth

Your code looks fine to me. Like the person above said I think you should change those symbols to && to avoid errors.
Topic archived. No new replies allowed.