Hello pops9432,
I have loaded your program and made some changes because with the code you posted it would not compile.
I offer this as a suggestion. Not that the program is right, but for form and style of what you could do.
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
|
#include <iostream>
#include <cmath>
#include <limits>
//using namespace std; // <--- Best not to use.
int main()
{
constexpr double LBSGROUT{ 0.13 }; // <--- Pounds of grout per one square foot. Or use "const".
double LengthInFeet{};
double WidthInFeet{};
double DimensionOfRoom = LengthInFeet * WidthInFeet;
double LengthInInches{};
double WidthInInches{};
double DimensionOfTiles = LengthInInches * WidthInInches;
double CostOfTiles{};
double PriceOfGroutRequired{}; // <--- Changed
double grout = DimensionOfRoom * LBSGROUT; // <--- Changed
std::cout << "What is the length of the room in feet? ";
std::cin >> LengthInFeet;
std::cout << std::endl;
std::cout << "What is the width of the room in feet? ";
std::cin >> WidthInFeet;
std::cout << std::endl;
std::cout << "Cost of tiles = ";
std::cin >> CostOfTiles;
std::cout << std::endl;
std::cout << "Grout: " << grout << std::endl;
// <--- Used to keep the console window open in Visual Studio Debug mode.
// 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; // <--- Not really necessary, but good form.
}
|
On line 6. At the end I basically pressed backspace and enter to put the opening "{" at the beginning of the next line. I am nor saying that there is anything wrong with what you did, but this way it is easy to see in your original code that the closing brace of main is missing because it would line up in the same column as the opening brace and easier to see that the closing brace is missing. And along with proper indenting you will see hoe this work better.
Line 8. The "0.13" that you used is called a magic number and should be avoided. Defining the variable as a constant solves this problem and gives you one place to make changes if needed. It also means the this variable can not be changed in the program. The capital letters remind you that the variable is defined as a constant. "constexpr" is a newer for of "const". It is used from C++11 on.
You have a problem with your original lines of:
1 2 3
|
float LengthInFeet;
float WidthInFeet;
float DimensionOfRoom = LengthInFeet*WidthInFeet;
|
Line 3. Is setting "DimensionOfRoom" equal to "LengthInFeet * WidthInFeet", but "Length" and "Width" have no value at this point except what is in the memory at the time th program is run. On my computer "Length" and "Width" have the value of "-9.2559631349317831e+61". Not a good number to use. This is known as a "garbage" and not something you want to use.
Although line 3 is totally wrong this is a good example for initializing your variables when defined. If you had initialized your "Length" and "Width" variables they would be "0.0" and "DimensionOfRoom" would be "0.0" which would work.
I have found the easiest way to initialize a variable is with, the uniform initializer, a set of {}s. An empty set will initialize a "double' to "0.0", and "int" types to zero. You can also put a number inside the {}s if you need to. Strings and some other types are empty to start with and do not need initialized.
The biggest point for line 3 is that is is to be given a value after your "std::cin" statements.
The same applies to the next three lines.
Your lines 24 and 24 are OK there, but my personal choice is to put all the variables in one place so I know where to find them. I have read that you should define variables just before you use them, but unless you do something to make them stand out they can be hard to find. And yes the "find" in the editor can help find the variable. That is what I learned when I started with C and it has been that way ever since.
If you look at my code you will see that some blank lines makes the code easier to read. Since the compiler does not care about blank lines or white space it is better to make the code easier to read both for you and others.
You have a start to your program, but you need a few more variables and at lease one other constant to deal with changing "square feet" to "square inches".
• 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.
|
So far you have covered the first step. You did miss the first part of second step, but did cover the second part. Steps three and four can only be done after you have made all your input.
Your line 25 will not work at all. You can not set a variable to "for()". "for()" is the start of defining a for loop and what you have is not complete.
The last five lines just before the "return" state are what I use to keep the console window open in my IDE when run in Debug mode. You may or may not need this with what you use, but it is yours to use if you need it.
A last thought in lines 13 and 17 I put a space on either side of the "*". It is not necessary, but does make the line easier to read.
Looking at the second link I gave you earlier. Think of each bullet as one piece of puzzle that needs to be done. It is better to work on one small piece than the whole program.
First get all the input that you can and get it working the way you want before you try to do calculations. It makes your life much easier.
One part that I can commend you on is the way you have your "cout" prompts followed by the "cin". To me keeping the prompt and input all on one line is much neater.
Hope that helps,
Andy