Need help with an assignment.

I am new to C++ programming so I need help with a question. Please I Really need help. Anyone can give me some pointers on what to do?


Question 2

Welcome to Sally's One Stop Tile Shop! Sally's One Stop Tile Shop specializes in tiles imported
from Spain, Italy, Brazil, and other countries. After purchasing their tiles, customers normally
purchase the grout and thin set that are required for the tiling job. So, Sally would like you to write
a program that will automatically generate an invoice for her customers based on the following:
• The dimension of the room to be tiled (expressed in feet)
• The dimension of the tiles to be used (expressed in inches) and the cost of the tile
• Grout is sold in 25 pound bags at $60.00 per bag and 0.13 pounds of grout is required for
each square foot of the tiling area.
• Thinset is sold in 50 pound bags at $45.00 per bag and a bag of thinset is required for 90
square feet of the tiling area.
• Grout and thinset are sold in bags. Portions of a bag cannot be purchased.
• VAT is calculated at the rate of 12.5% of the overall total.
Write a program, Invoice.cpp, to prompt the user for the dimensions of the room and the
dimensions and cost of the tiles and generate the invoice for Sally’s customers. Appropriate labels
must be used. Test your program to ensure that it is working correctly.
Points to Note for Question 2:
• You can assume that the room and tiles are rectangular.
• ceil (x) can be used to round x to the smallest integer not less than x.
For example: ceil (9.0) is 9, ceil (9.2) is 10, and ceil (9.9) is 10.
• To use ceil (x), place the following line before main():#include <cmath>

And yes I have tried to attempt it. It's terribly coded because I don't understand some things.
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
#include <iostream>
using namespace std;
#include <cmath>
int main(){
	int feet_long;
	int feet_wide;
	int inches_long;
	int inches_wide;	
	int grout;
	int area;
	int area_tile;
	grout=25;
	int price_grout;
	price_grout=60;
	int thinset;
	thinset=50;
	int price_thinset;
	price_thinset=45;
	int number_tiles;
	int one_tile;
cout<<"Please enter the length of the room: ";
cin>>feet_long;
cout<<"Please enter the width of the room: ";
cin>>feet_wide;
cout<<"Please enter the length of the tile: ";
cin>>inches_long;
cout<<"Please enter the width of the tile: ";
cin>>inches_wide;
cout<<"Cost of one tile ";
cin>>one_tile;
area=feet_long*feet_wide;
area_tile=inches_long*inches_wide;
number_tiles=(area*144)/area_tile;
float bags_thinset;
bags_thinset=ceil(area/90)*50;
float pound_grout;
pound_grout=ceil(0.13*area_tile);
int total;
total=(one_tile*number_tiles)+(price_grout*pound_grout)+(price_thinset*bags_thinset);
cout<<"Length of the room: "<<feet_long<<endl;
cout<<"Width of the room: "<<feet_wide<<endl;
cout<<"Length of the tile: "<<inches_long<<endl;
cout<<"Width of the tile: "<<inches_wide<<endl;
cout<<"Area of the room: "<<area<<endl;
cout<<"Area of the tiles: "<<area_tile<<endl;
cout<<"Number of tiles: "<<number_tiles<<endl;
cout<<"Pounds of Grout needed: "<<pound_grout<<endl;
cout<<"Bags of Thinset needed: "<<bags_thinset<<endl;
cout<<"Total: "<<total<<endl;

	
}
Last edited on
Please note that this is not a homework site. We won't do your homework for you. The purpose of homework is that you learn by doing. However we are always willing to help solve problems you encountered, correct mistakes you made in your code and answer your questions.

We didn't see your attempts to solve this problem yourself and so we cannot correct mistakes you didn't made and answer questions you didn't ask. To get help you should do something yourself and get real problems with something. If your problem is "I don't understand a thing", then you should go back to basics and study again.

For example, the http://www.cplusplus.com/doc/tutorial/ has some basics.
Hello CheesyForde1,

To help you get started:


Welcome to Sally's One Stop Tile Shop! Sally's One Stop Tile Shop specializes in tiles imported
from Spain, Italy, Brazil, and other countries. After purchasing their tiles, customers normally
purchase the grout and thin set that are required for the tiling job. So, Sally would like you to write
a program that will automatically generate an invoice for her customers based on the following:

• The dimension of the room to be tiled (expressed in feet)

• The dimension of the tiles to be used (expressed in inches) and the cost of the tile

• Grout is sold in 25 pound bags at $60.00 per bag and 0.13 pounds of grout is required for
each square foot of the tiling area.

• Thinset is sold in 50 pound bags at $45.00 per bag and a bag of thinset is required for 90
square feet of the tiling area.
• Grout and thinset are sold in bags. Portions of a bag cannot be purchased.

• VAT is calculated at the rate of 12.5% of the overall total.

Write a program, Invoice.cpp, to prompt the user for the dimensions of the room and the
dimensions and cost of the tiles and generate the invoice for Sally’s customers. Appropriate labels
must be used. Test your program to ensure that it is working correctly.
Points to Note for Question 2:

• You can assume that the room and tiles are rectangular.

• ceil (x) can be used to round x to the smallest integer not less than x.
For example: ceil (9.0) is 9, ceil (9.2) is 10, and ceil (9.9) is 10.

• To use ceil (x), place the following line before main():#include <cmath>


I find that breaking up the instructions like this breaks the program into smaller pieces that you can work on one at a time.

To start with you could ask for the customers name,address,phone number and e-mail followed by the first two points of the room dimensions and tile dimensions.

The next to last is something to be considered when you start writing the program because of the header file that needs included. Of-course this can always be added later to the header file includes.

Hope that helps,

Andy
It's terribly coded because I don't understand some things.
. What is it that you do not understand?
As @keskiverto say
we cannot ... answer questions you didn't ask
, be specific and you will will most likely get the help you need.
Last edited on
There exists at least three problem types:
1. Code does not compile if it has syntax errors. Compiler error messages are important.
2. Program does crash. Error in logic.
3. Unexpected results. Error in logic.

You did add your code, so I'll give you one:
1
2
3
int area;
float bags_thinset;
bags_thinset = ceil( area / 90 ) * 50;

The area is an int and the 90 is an int.
Therefore, the area / 90 is an integer operation and produces an int.
Integer division discards the fraction.
For example, when area==89, 89/90==0 and ceil(89/90)==0. The ceil() is helpless.

If at least one operand in the division is float, then the division operation becomes float.
Division has two operands.
area / 90.0 (int/double)
static_cast<float>(area) / 90 (float/int)
(The cast does not modify the area, it just creates a float copy of the value of the area.)
Hello CheesyForde1,

My first tip is not to change anything in what you have posted, but to post a new message. It tends to confuse people and makes the thread hard to follow. That said adding the code to your original post, OP as you will later see in other messages which can refer to either the original message or the person, in this case is not a problem.

Do not feel bad about your code I have seen worse. To that I offer this suggestion:

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
#include <iostream>
#include <iomanip>  // <--- For "std::setprecision" and "std::setw".
#include <limits>
#include <cmath>

//using namespace std;  // <--- Best not to use.


int main()
{
	constexpr double GROUT{ 25.0 };
	constexpr double PRICE_GROUT{ 60.0 };
	constexpr double THINSET{ 50.0 };
	constexpr double PRICE_THINSET{ 45.0 };
	constexpr double SQUAREFOOT(144.0);  //<--- Added.
	constexpr double AREA_COVERED_BY_THINSET{ 90.0 };  //<--- Added.
	constexpr double SQR_FOOT_GROUT_COVERAGE{ 0.13 };  //<--- Added.

	double feet_long{}, feet_wide{}, inches_long{}, inches_wide{};
	double /*grout{}, */area{}, area_tile{}/*, price_grout{}*/;

	//double thinset{};
	//double price_thinset{};

	double number_tiles{};
	double one_tile{};
	double total{};
	double bags_thinset{};
	double pound_grout{};


	std::cout << "Please enter the length of the room: ";
	std::cin >> feet_long;

	std::cout << "Please enter the width of the room: ";
	std::cin >> feet_wide;

	std::cout << "Please enter the size of the tile: ";  // <--- Changed.
	std::cin >> inches_long;
	inches_wide = inches_long;  // <--- Changed.

	//std::cout << "Please enter the width of the tile: ";
	//std::cin >> inches_wide;

	std::cout << "Cost of one tile ";
	std::cin >> one_tile;

	area = feet_long * feet_wide;

	area_tile = inches_long * inches_wide;

	number_tiles = (area * SQUAREFOOT) / area_tile;

	bags_thinset = ceil(area / AREA_COVERED_BY_THINSET) * 50;

	pound_grout = ceil(SQR_FOOT_GROUT_COVERAGE * area_tile);

	total = (one_tile * number_tiles) + (PRICE_GROUT * pound_grout) + (PRICE_THINSET * bags_thinset);

	std::cout << std::fixed << std::showpoint << std::setprecision(2);  // <--- Added.

	std::cout << '\n' << std::setw(20) << "Length of the room: " << feet_long << " feet" << std::endl;
	std::cout << std::setw(20) << "Width of the room: " << feet_wide << " feet" << std::endl;

	std::cout << '\n' << std::setw(20) << "Length of the tile: " << inches_long << " inches" << std::endl;
	std::cout << std::setw(20) << "Width of the tile: " << inches_wide << " inches" << std::endl;

	std::cout << '\n' << std::setw(20) << "Area of the room: " << area << " square feet" << std::endl;

	std::cout << std::setw(20) << "Area of the tiles: " << area_tile << " square inches" << std::endl;

	std::cout << std::setw(20) << "Number of tiles: " << number_tiles << std::endl;

	std::cout << '\n' << std::setw(20) << "Pounds of Grout needed: " << pound_grout << std::endl;

	std::cout << std::setw(20) << "Bags of Thinset needed: " << bags_thinset << std::endl;

	std::cout << '\n' << std::setw(20) << "Total: " << total << std::endl;

	// The next line may not be needid. If you have to press enter to see the prompt it is not needed.
	std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');  // <--- Requires header file <limits>.
	std::cout << "\n\n Press Enter to continue";
	std::cin.get();

	return 0;
}

At the top of the program are all the "#include" files. If you do enough reading here and elsewhere you will see that the "#include"s generally come first.

Next is usually any header file that is wrapped in Quotes ("").

You should learn to avoid using line 6 as it WILL get you in trouble some day. As you read through the program you will see how and what I qualified in the standard name space. Right now it would seem to make coding easier, but it does not in the future.

Inside "main" I created constant variables with the key work "constrxpr". If this is a problem for your compiler the older version of "const" works just fine. Also notice that the name is in all caps. This helps to remind you that the variable is a constant that can not be changed in the program. The compiler will also give you an error if you try to change a constant variable.

Also notice the empty {}s after the variable name. This is the uniform initializer. The empty {}s will initialize the variable to zero. In this case a double would end up as 0.0.

Lines 19 and 20 are just another way of defining several variables on one line to save some space. If you do not have many variables I suggest using one line per variable. Some variables do not really need initialized because the next part of the program will use "cin" to give them a value, but I like to initialize a variable when it is defined just to be safe.

The variables that are commented out I left to show you that they are no longer needed because they are replaced by the constant variables.

In the input section I changed the input for tile dimensions to just one input then set the width equal to the length. This way you do not have to change the program later to deal with just one number. As far as I have ever seen tiles are square, so one number will fit all sides. If you need to enter it twice it is easy to change back.

In the section for the calculations the two for area are OK, but I am nor sure about the rest as of now. In your original code you used what is call "magic numbers". It does work, but not the best way to write a program. As you can see in my code I have replaced these "magic numbers" with the constants that I defined at the beginning of the function. The only line I am not sure of is bags_thinset = ceil(area / AREA_COVERED_BY_THINSET) * 50;. I am not sure what to call a variable for the "50" or even what it is used for right now.

The last section is the "cout" statements. I made some changes to these lines to format what is displayed on the screen, but this is good for testing, but it does not create the invoice that the instructions ask for. This can easily fixed.

The last four lines before the "return" is what I sue to keep the console window open when I run the program from my IDE. You can use it or disregard it if you do not need it.

Last point. The way you wrote your original code as one block is OK the compiler does not case. If you look at my code the blank lines break up the code and make it easier to read. The easier it is to read the easier it is to work with. And if you add a comment line for each section it will help everyone to find things. Sorry the only part i did not think of at the time i was working on the program.

Hope that helps,

Andy

Sorry I didn't specify the problem. It was the maths of the problem and also how I coded it. But I do appreciate the help. I will try to finish the rest of the problem. However andy, I will learn not to use line 6 but for now my teacher uses it so I quess she expects me to use it at this time. Also you made a good point to break up the code so that others can actually read and point out what's wrong. Thank you. The problem actually says that to assume the tiles are rectangular so I kinda have to give what it asks for. Though you helped me alot. Thanks man.
Hello CheesyForde1,

You are welcome. I am glad that you got something out of it.

Just because your instructor uses using namespace std; does not make it right. In the end it is your choice to just follow along or learn the right way. I am not here to force it on you.

I looked back over the instructions and did not see anything that the tiles are rectangular. Maybe that was in something you did not post. Easy enough to leave the code the way you had it to enter a number for "length' and "width".

Andy
Topic archived. No new replies allowed.