0
#include <iostream>
using namespace std;

void GetRoomTiles(int WidthFeet, int WidthInches, int &TotalWidth, int LengthFeet, int LengthInches, int &TotalLength, int TileSize, int &RoomTiles);
void GetTotalTiles(int RoomTiles, int &TotalTiles);
void GetNumberOfBoxes(int TotalTiles, int TileBoxes, int &ExtraTiles, int &NumberOfBoxes);

int main()
{
    int NumberOfRooms;
    int TileSize;
    int WidthFeet, WidthInches, TotalWidth;
    int LengthFeet, LengthInches, TotalLength;
    int RoomTiles, TotalTiles;
    int NumberOfBoxes = 0;
    int TilesBoxes = 20;
    int ExtraTiles = 0;
    ExtraTiles++;
    
          
          cout << "Enter the number of rooms needed for tiles:";
          cin >> NumberOfRooms;
    
    if (NumberOfRooms <= 0)
    cout << "Please re-enter a positive value greater than 0." << endl;
    TileSize = -1;
                        
                        cout <<"Enter the size of tile in inches.";
                        cin >> TileSize;
                        
                        if (TileSize <= 0)
                        cout << "Please re-enter the positive value greater than 0." << endl;
                        
                        if (TileSize <= 11)
                        cout << "Make sure to enter inches greater than 11." << endl;
                        
                        WidthFeet = -1;
                        WidthInches = -1;
                        
    while((WidthFeet <= 0) && (WidthInches <= 0))
    {
                     cout << "Enter room width (feets and inches, separated by space)" << endl;
                     cin >> WidthFeet >> WidthInches;
    if((WidthFeet <= 0) && (WidthInches <= 0))
    cout << "Please re-enter positive values dimensions greater than 0." << endl;
}
    LengthFeet = -1;
    LengthInches = -1;
    
    while((LengthFeet <= 0) && (LengthInches <= 0))
    {
                      cout << "Enter room length (feets and inches, separated by space)" << endl;
                      cin >> LengthFeet >> LengthInches;
    if((LengthFeet <= 0) && (LengthInches <= 0))
    cout << "Please re-enter positive values dimensions greater than 0." << endl;
    
    GetRoomTiles(WidthFeet, WidthInches, TotalWidth, LengthFeet, LengthInches, TotalLength, TileSize, RoomTiles);
    GetTotalTiles(RoomTiles, TotalTiles);
}
    
    GetNumberOfBoxes(TotalTiles, TilesBoxes, ExtraTiles, NumberOfBoxes);
    
    system("pause");
    return 0;
}
    
void GetRoomTiles(int WidthFeet, int WidthInches, int &TotalWidth, int LengthFeet, int LengthInches, int &TotalLength, int TileSize, int &RoomTiles)
{
     TotalWidth = ((WidthFeet * 12) + WidthInches);
         cout << "Total Width in inches is " << TotalWidth << endl;
     TotalLength = ((LengthFeet * 12) + LengthInches);
         cout << "Total Length in inches is " << TotalLength << endl;
 
    RoomTiles = ((TotalWidth / (TileSize - 1)) * (TotalLength / (TileSize - 1)));
         cout << "The room requires: " << RoomTiles << " tiles." << endl;
}
void GetTotalTiles(int RoomTiles, int &TotalTiles)
{
     TotalTiles += RoomTiles;
         cout << "Total tiles required: " << TotalTiles << endl;
}
void GetNumberOfBoxes(int TotalTiles, int TilesBoxes, int &ExtraTiles, int &NumberOfBoxes)
{
     ExtraTiles = TotalTiles / TilesBoxes;
     NumberOfBoxes = ((TotalTiles + ExtraTiles) / TilesBoxes);
         cout << "The total number of boxes needed is: " << NumberOfBoxes << endl;
         cout << "There will be " << ExtraTiles << " extra tiles." << endl;
}

Alright guys this is what I've come up. It complied fine. And actually the stuff for the Room Tiles is actually correct, but the Number Of Boxes, Extra Tiles, and Total Tiles. are still off. What am I doing wrong? and how do I fix it?

This is what I'm doing:

Need to estimate the number of boxes of tile for a job. A job is estimated by taking the dimensions of each room in feet and inches and converting these dimensions into a multiple of the tile size (rounding up any partial multiple) before multiplying to get the number of tiles for the room. A box contains 20 tiles, so the total number needed should be divided by 20 and rounded up to get the number of boxes. The tiles are assumed to be square.

Program should prompt user for size of the tile in inches and the number of rooms to be covered with tile. It should then input the dimensions for each room and output the number of tiles needed for that room. After data for the last room is input the program should output the total number of tiles needed, the number of boxes of tile needed and how many extra tiles will be left over.

Use functional decomposition to solve this problem and code the solution using functions wherever it makes sense to do so. Your program should check for invalid data such as non-positive dimensions, number of rooms less than one, number of inches greater than 11, and so on. It should prompt the user for corrected input whenever it detects invalid input. Now that your programs are becoming more complex it is even more important for you to use proper indentation and style, meaningful identifiers and appropriate comments.

I know you guys have stuff like this getting on your nerves, but I nearly figured it all out. I just need to know how to completely fix it so I can be happy of what I did to make sure I finished it all correctly.

Sorry for the inconvience, and I'm gonna go delete my previous thread now.

Edited by nekoleon64: n/a

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by VernonDozier
0

I would change a few variable names, sticks some prepositions in there, or something like that. The variable names, while descriptive, aren't descriptive enough. I want to be able to read the probram and figure out whether the math flows correctly, but TilesBoxes could mean NumBoxesOfTiles, NumTilesThatFitInAInASingleBox, NumTilesInBoxes, etc. It turns out to be the middle one. The only way I figured that out was looking up a constant I could use (20), and finding the variable that goes with it.

Look at this line...

ExtraTiles = TotalTiles / TilesBoxes;

ExtraTiles -- what's that? The tiles that are left over lying on the floor while all the other tiles are in nice boxes of 20?

So I have 10,010 tiles, 10,000 of them are in boxes, and there are ten "extra" tiles? Is that the idea? Now look at the line and plug those numbers in and see if that formula makes sense.

>> Alright guys this is what I've come up. It complied fine. And actually the stuff for the Room Tiles is actually correct, but the Number Of Boxes, Extra Tiles, and Total Tiles. are still off. What am I doing wrong? and how do I fix it?


As to the overall thread, more info is needed. You mention that it compiles. That's good. You mentioned what worked and what didn't. Good. What you didn't do is give is the input you used, the correct output, the actual output, and point out the differences. That allows us to run the program and recreate exactly what you did and zone in very fast on the error.

Edited by VernonDozier: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.