Here is my problem
I am trying to write a program that will estimate the number of boxes of tile needed for a job. A job is estimated by taking the dimensions of each room in feet and inches and converting these 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 should have 20 tiles, so I need to divide the total number needed by 20 and rounded up to get the number of boxes (they are square). Here is what I have so far:

``````#include <iostream>
#include <cmath>
#include <iomanip>
#include <fstream>
using namespace std;
// Function prototypes
void DetermineTileno(float, float, int, int, float&);
void PrintResults( float, float, int, int, float);
int main()
{
// Input Variables
float roomNumber;
float tileSize;
int roomLength;
int roomWidth;
float tileNo;

// Prompt for and read Room Number
cout << "Input the total number of rooms to be tiled: " << endl;
cin >> roomNumber;
// the tile size is the same for all rooms
// Prompt for and read tile size, room width, room length.
cout << "Input the size of tile in inches:" << endl;
cin >> tileSize;
// Loop calculating room number
while (roomNumber >= 1)
{
}
struct _roomdim;
{
int feet, inches;
roomLength, roomWidth;

}
cout << "Input the width of room (feet and inches, seperated by "
<< "a space):" << endl;
cin >> roomWidth.feet >> roomWidth.inches;
cout << "Input the length of room (feet and inches, seperated"
<< " by a space):" << endl;
cin >> roomLength.feet >> roomLength.inches;

DetermineTileno(roomNumber, tileSize, roomLength, roomWidth,
tileNo);
PrintResults( roomNumber, tileSize, roomLength, roomWidth,
tileNo);

{
// local variables
float roomSize;
int tileCoverage;

roomSize = roomLength * roomWidth;
tileCoverage = tileSize * 20;
tileNo = ((roomSize)/(tileCoverage));
}
// dataOut.close();
cin.get();
cin.get();
return 0;
}``````

I get many errors when trying to compile this, and I also need to know what I can do to get it to give me a correct output of tiles needed. I am so confused on this!! Thanks in advance for any help you guys/gals can offer!

Emily

## All 9 Replies

Hello, I couldnt get wt u r trying to do !
but i can tell that ya have problem with structers and functions...
anyways i wrote a hard coded program for you(probably its not what you trying to prove !)...try to use some functions!
cheers !

``````#include <iostream>
using namespace std;
struct _roomdim
{
int feet, inches;
} roomLength, roomWidth;
int main()
{
float roomNumber;
float tileSize;
cout << "\nInput the total number of rooms to be tiled: " << endl;
cin >> roomNumber;
cout <<"\nroomNumbeR:"<<roomNumber;
cout << "\nInput the size of tile in inches:" << endl;
cin >> tileSize;
cout <<"\ntileSize:"<<tileSize;
cout <<"\nInput the width of room (feet and inches, seperated by "
<< "a space):" << endl;
cin >> roomWidth.feet >> roomWidth.inches;
cout<<"\nroomWidth.feet:"<<roomWidth.feet<<"roomWidth.inches:"<<roomWidth.inches<<endl;
cout << "Input the length of room (feet and inches, seperated"
<< " by a space):" << endl;
cin >> roomLength.feet >> roomLength.inches;
cout<<"\nroomLength.feet:"<<roomLength.feet<<"roomLength.inches:"<<roomLength.inches<<endl;
int roomWidthT=roomWidth.feet * roomWidth.inches;
cout <<"\nroomWidthT:"<<roomWidthT<<endl;
int roomLengthT=roomLength.feet * roomLength.inches;
cout <<"\nroomLengthT:"<<roomLengthT<<endl;
float roomSize=roomWidthT*roomLengthT;
cout<<"\nroomSize:"<<roomSize<<endl;
int tileCoverage =tileSize * 20;
cout<<"\nTileCoverage:"<<tileCoverage<<endl;
float tileNo = ((roomSize)/(tileCoverage));
cout<<"\nTileNumber:"<<tileNo<<endl;
cout<<"total number of tiles for all rooms"<<tileNo*roomNumber<<endl;
return 0;
}``````
``````#include<iostream>
#include <cmath>
#include <iomanip>
#include <fstream>
using namespace std;
struct _roomdim
{
int feet, inches;
} roomLength, roomWidth;
int main()
{
// input variables
float roomNumber;
float tileSize;

cout << "\nInput the total number of rooms to be tiled: " << endl;
cin >> roomNumber;
cout << "\nInput the size of tile in inches:" << endl;
cin >> tileSize;
cout <<"\ntileSize:"<<tileSize;
cout <<"\nInput the width of room (feet and inches, seperated by "
<< "a space):" << endl;
cin >> roomWidth.feet >> roomWidth.inches;
cout<<"\nroomWidth.feet:"<<roomWidth.feet<<"roomWidth.inches:"<<roomWidth.inches<<endl;
cout << "Input the length of room (feet and inches, seperated"
<< " by a space):" << endl;
cin >> roomLength.feet >> roomLength.inches;
cout<<"\nroomLength.feet:"<<roomLength.feet<<"roomLength.inches:"<<roomLength.inches<<endl;
int roomWidthT = ((roomWidth.feet) * (roomWidth.inches));
cout <<"\nroomWidthT:"<<roomWidthT<<endl;
int roomLengthT = ((roomLength.feet) * (roomLength.inches));
cout <<"\nroomLengthT:"<<roomLengthT<<endl;
float roomSize = ((roomWidthT)*(roomLengthT));
cout<<"\nroomSize:"<<roomSize<<endl;
int tileCoverage = ((tileSize) * (20));
cout<<"\nTileCoverage:"<<tileCoverage<<endl;
float tileNo = ((roomSize)/(tileCoverage));
cout<<"\nTileNumber:"<<tileNo<<endl;
cout<<"total number of tiles for all rooms"<< ((tileNo)*(roomNumber))<<endl;

cin.get();
cin.get();
return 0;``````

Here are the hints I was given
This problem also requires you to have a good understanding of data types and the capabilities and limitations of int and float variables. In my discussion of this algorithm the use of the word "get" is the equivalent of the "cin".
Get the number of rooms.
Get the tile size in inches. We are given that the tile is a square, thus the length and width of the tile are the same.
Start of main loop
The number of rooms is the control variable for your main logic loop. You will repeat this logic for each room and exit the loop only when the necessary information has been determined for all rooms.
Room logic
Get the width and length of the room in feet and inches.
The smallest unit of measurement is the inch. Therefore, you calculate the number of inches for the width dimension and the number of inches for the length dimension.
Given this, you determine the number of tiles it will take for each dimension. You must take into account the affects of fractional tiles and roundup to determine the number of "whole" tiles. For example, if the tile size is 12 inches and the room width is 10 feet and 4 inches, the width in inches is 124 inches. Thus the number of tile to go across the width is 10.333 or 11 tiles.
You do the same for the length dimension. The number of tiles required for the room is simply the number of tiles in the length dimension times the number of tiles in the width dimension. (Remember the formula for the area of a rectangle?)
You repeat the above for each room, accumulating the total number of tiles required room by room.
End of main loop.
You now know the total number of tiles required and you must now determine the number of boxes of tiles required. You are given that there are 20 tiles per box. You can not have a fractional number of boxes. Once you determine the number of boxes, the extra tiles should be very easy to calculate.

Thanks for the help!!

Emily

It would really your problem if you could create different functions for different tasks like: 1. Accepting the data 2. Performing the conversions 3. Performing the calculations for the number of tiles. If classes have been introduced in your course you can try creating a class "Room" which will pack all the data and functions in a single abstraction. Incorporate the followign changes and repost. It will also help you get good grades if you perform the task using functions.

``````#include<iostream>
#include <cmath>
#include <iomanip>
#include <fstream>
usingnamespace std;
struct _roomdim
{
int feet, inches;
} roomLength, roomWidth;
int main()
{
// input variables
float roomNumber;
float tileSize;

// Input Number of Rooms
cout << "\nInput the total number of rooms to be tiled: " << endl;
cin >> roomNumber;

//Input Tile Size
cout << "\nInput the size of tile in inches:" << endl;
cin >> tileSize;
cout <<"\ntileSize:"<<tileSize;

// Input Width of room
cout <<"\nInput the width of room (feet and inches, seperated by "
<< "a space):" << endl;
cin >> roomWidth.feet >> roomWidth.inches;
cout<<"\nroomWidth.feet:"<<roomWidth.feet<<"roomWidth.inches:"<<roomWidth.inches<<endl;

// check for errors
if (roomWidth.inches > 11)
cout <<"please use correct inches if over 11 inches make it foot." << endl;
cout <<"Input the width of room (feet and inches, seperated by "
<< "a space):" << endl;

// Input Length of room
cout << "Input the length of room (feet and inches, seperated"
<< " by a space):" << endl;
cin >> roomLength.feet >> roomLength.inches;
cout<<"\nroomLength.feet:"<<roomLength.feet<<"roomLength.inches:"<<roomLength.inches<<endl;

// Check for errors
if (roomLength.inches > 11)
cout << " please use correct inches if over 11 inches make it a foot." << endl;
cout << "Input the length of room (feet and inches, seperated"
<< " by a space):" << endl;

// Varibles for Room Tile coverage and Length/Width
int roomWidthT = ((roomWidth.feet) * (roomLength.feet));
cout <<"\nroomWidthT:"<<roomWidthT<<endl;
int roomLengthT = ((roomLength.inches) * (roomWidth.inches));
cout <<"\nroomLengthT:"<<roomLengthT<<endl;
float roomSize = ((roomWidthT)+ (roomLengthT));
cout<<"\nroomSize:"<<roomSize<<endl;
int tileCoverage = ((tileSize) * (20));
cout<<"\nTileCoverage:"<<tileCoverage<<endl;
float tileNo = ((tileCoverage)/(roomSize));
cout<<"\nTileNumber:"<<tileNo<<endl;
cout<<"total number of tile boxes for all rooms "<< ((tileNo)*(roomNumber))<<endl;

cin.get();
cin.get();
return 0;

}``````

Here is what I have revampped so far, I think it for the most part works. But I can't figure out how to get my loop back in there for room numbers greater than 1 when I put it in it screws the code up. Thanks in Advance for advice on where to put my roomNumber Loop!

``````#include<iostream>
#include <cmath>
#include <iomanip>
#include <fstream>
usingnamespace std;
struct _roomdim
{
int feet, inches;
} roomLength, roomWidth;
int main()
{
// input variables
float roomNumber;
float tileSize;

// Input Number of Rooms
cout << "\nInput the total number of rooms to be tiled: " << endl;
cin >> roomNumber;

//Input Tile Size
cout << "\nInput the size of tile in inches:" << endl;
cin >> tileSize;
cout <<"\ntileSize:"<<tileSize;

// Input Width of room
cout <<"\nInput the width of room (feet and inches, seperated by "
<< "a space):" << endl;
cin >> roomWidth.feet >> roomWidth.inches;
cout<<"\nroomWidth.feet:"<<roomWidth.feet<<"roomWidth.inches:"<<roomWidth.inches<<endl;

// check for errors
if (roomWidth.inches > 11)
cout <<"please use correct inches if over 11 inches make it foot." << endl;
cout <<"Input the width of room (feet and inches, seperated by "
<< "a space):" << endl;

// Input Length of room
cout << "Input the length of room (feet and inches, seperated"
<< " by a space):" << endl;
cin >> roomLength.feet >> roomLength.inches;
cout<<"\nroomLength.feet:"<<roomLength.feet<<"roomLength.inches:"<<roomLength.inches<<endl;

// Check for errors
if (roomLength.inches > 11)
cout << " please use correct inches if over 11 inches make it a foot." << endl;
cout << "Input the length of room (feet and inches, seperated"
<< " by a space):" << endl;

// Varibles for Room Tile coverage and Length/Width
int roomWidthT = (((roomWidth.feet) * 12) + (roomWidth.inches));
cout <<"\nroomWidthT:"<<roomWidthT<<endl;
int tileWidth = ((roomWidthT / 12));
cout <<"\ntileWidth:"<<tileWidth<<endl;
int roomLengthT = (((roomLength.feet) * 12) + (roomLength.inches));
cout <<"\nroomLengthT:"<<roomLengthT<<endl;
int tileLength = ((roomLengthT / 12));
cout <<"\ntileLength:"<<tileLength<<endl;

float roomSize = ((roomWidthT)+ (roomLengthT));
cout<<"\nroomSize:"<<roomSize<<endl;
float tileNo = (((tileWidth) * (tileLength)));
cout<<"\nTileNumber:"<<tileNo<<endl;
cout<<"total number of tile boxes for all rooms "<< ((tileNo)/(20))<<endl;

cin.get();
cin.get();
return 0;

}``````

Okay it works mathmatically, but I can't loop it to do more than one room.. where do I stick my loop in. I have tried everywhere and it give me errors. I need it to loop for number of rooms>1

Think about it logically, where do you need to keep the loop. It should be obvio after the variables required throughout the prog have been entered by the user. So the loop should logically be placed before the block when you start accepting theroom specs from the user. Hence place the loop after you ask the number of rooms and the tile size from the user.

``````// Input Number of Rooms
cout << "\nInput the total number of rooms to be tiled: " << endl;
cin >> roomNumber;

//Input Tile Size
cout << "\nInput the size of tile in inches:" << endl;
cin >> tileSize;
cout <<"\ntileSize:"<<tileSize;
while (roomNumber);
{ if (roomNumber >1);
}``````

If i put it in like this my program stops running right there. I guess I am over thinking it LOL.. but I am so LOST

``````for( int i = 0; i < roomNumber; ++i )
{
// do what you want here
}``````

Thanks so much. I had to scrap all of that and put my functions back in LOL... now it works perfect!! Thanks for all the help!! :cheesy:

``````for( int i = 0; i < roomNumber; ++i )