I need some help,Here is the problem, I work for a company that lays ceramic floor tile and I need a program that estimates 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 multiple of the tile size(round up any partial multiple) before multipylying 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 round up to get the number of boxes. the tiles are assumed to be square. The program should initially prompt the user for the size of the tiles in inches, and the number of rooms to be input. It should then input the dimensions for each room, and output the tiles needed for that room. After the last room is input, the program also should output the total number of tiles needed, the number of boxes needed, and how many extra tiles will be left over.


Gives all the numbers the book asks ]for although I didn’t use any functions. It also needs a way to check for invalid inputs like 13 for inches and number of rooms < 0. I’ll keep working on it. Didn’t you get some code from that programming website? Send me what you got, maybe it’ll give me some ideas.

// 
#include "stdafx.h"
#include <iostream>

using namespace std;

int main()
{
    int tileSize;
    int numOfRooms;
    int roomWidIn;
    int roomWidFt;
    int roomLenIn;
    int roomLenFt;
    int lenTot;
    int widTot;
    int tilesPerRm = 0;
    int totalTiles = 0;
    int numOfBoxes = 0;
    int a;

    cout << "Enter number of rooms: ";
    cin >> numOfRooms;
    cout << "Enter size of tile in inches: ";
    cin >> tileSize;
    
    while (numOfRooms > 0)
    {
        cout << "Enter room width (feet and inches, separated by a space): ";
        cin >> roomWidFt >> roomWidIn;
        cout << "Enter room length (feet and inches, separted by a space): ";
        cin >> roomLenFt >> roomLenIn;
        widTot = ((roomWidFt*12+roomWidIn)/tileSize);
        if (((roomWidFt*12+roomWidIn)%tileSize) != 0) ++widTot;
        lenTot = ((roomLenFt*12+roomLenIn)/tileSize);
        if (((roomLenFt*12+roomLenIn)%tileSize) != 0) ++lenTot;
        cout << "Room requires " << (widTot * lenTot) << " tiles." << endl;
        totalTiles = totalTiles + (widTot * lenTot);
        numOfRooms = numOfRooms - 1;
    }

    cout << "Total Tiles required is " << totalTiles << "." << endl;
    numOfBoxes = totalTiles/20;
    if ((totalTiles%20) != 0) ++numOfBoxes;
    cout << "Number of boxes needed is " << numOfBoxes << "." << endl;
    cout << "There will be " << (numOfBoxes*20) - totalTiles << " extra tiles." << endl;

    cin >> a;

    return 0;
}

Please use code tags.

It looks good, and I assume you know how to create functions. Functions are purely for organization, so you might want to do something like the following: validateRooms() - called by getNumRooms(), and validates the input (such as <0 and decimal numbers). getNumRooms() - asks the user for the number of rooms and returns the result. validateTileSize() - called by getTileSize(), validates the input. getTileSize() - Asks user for tile size and returns the input.

And so on. I hope you get the idea. Functions are also useful for debugging, because if you have a bug in the following lines of code:

function1();
function2();
function3();

you can debug each function by commenting out each one individually (assuming that the functions don't depend on each other). It's certainly a lot easier than commenting out huge blocks of code. Once you've found the function that has the bug, you can start debugging that single function.

I need some help,Here is the problem, I work for a company that lays ceramic floor tile and I need a program that estimates the number of boxes of tile for a job.

Somehow I don't believe you... Why not just admit that this is your homework?

One simple way to check for valid inputs (essentially ask the user again if the input is invalid) is to put your 'get' code inside a do..while loop. You could wrap it in a function aswell if you wish, for example:

#include <iostream>

int get_number_between(int lower, int upper)
{
    int in;
    do
    {
        std::cout << "Enter a number between " << lower << " and " 
            << upper << " inclusive:";
        std::cin >> in;
    }while ((in < lower) || (in > upper));
    return in;
}

int main()
{
    int x = get_number_between(0,100);
    std::cout << "User entered: " << x;
}

This isn't a perfect solution, and will invoke undefined behaviour if the user enters anything other than a number, although it provides a very basic form of input validation. You could improve it by adding checks on the state of the stream aswell.

I sorry I didn't mean to confuse anybody I am a student and it is a homework project I jsut though that you knew that I was a NEW BE at this and I like it but AGAIN I am new to all of this stuff. Again I sorry.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.