I have to write this program that prompts the user for the size of the tiles in inches and the number of rooms to be input. It should then input the dimensionsfor 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.

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.

Here is an example of how a run might appear:

Enter number of rooms: 2
Enter size of tile in inches: 12
Enter room width (feet and inches, separated by a space): 17 4
Enter room length (feet and inches, separated by a space): 9 3
Room requires 180 tiles.
Enter room width (feet and inches, separated by a space): 11 6
Enter room length (feet and inches, separated by a space): 11 9
Room requires 144 tiles.
Total tiles required is 324.
Number of boxes needed is 17.
There will be 16 extra tiles.

I used the same data from this example to check if my program was running correctly, but I'm doing some thing wrong because I don't get the right amount of tiles required for the rooms, and i can't get out of the loop.

Here is what I have so far:

#include <iostream>
using namespace std;

int main ()
{

  int tsize;                        [COLOR=Lime]// size of tiles in inches[/COLOR]
  int tiles= 0;
  int num_rooms;
  int w_inches;                  [COLOR=Lime]// inches of width of rooms[/COLOR]
  int l_inches;                   [COLOR=Lime]//  inches of length of rooms[/COLOR]
  int w_feets;                  [COLOR=Lime]// feet of width of rooms[/COLOR]
  int l_feets;                   [COLOR=Lime]// feet of length of rooms[/COLOR]
  int total_w_inches;          [COLOR=Lime]// total width of rooms in inches[/COLOR]
  int total_l_inches;              [COLOR=Lime]// total length of rooms in inches[/COLOR]
  int len;                       [COLOR=Lime]// number of tiles needed for the length[/COLOR]
  int wid;                      [COLOR=Lime]// number of tiles needed for the width[/COLOR]
  int bo;                         [COLOR=Lime]// number of boxes[/COLOR]

  cout << "Enter number of rooms" << endl;
  cin >> num_rooms;
  cout << "Enter size of tiles in inches" << endl;
  cin >> tsize;


  while ( num_rooms > 0 )
  {
    cout << "Enter room width (feet and inches, separated by a space):" << endl;
    cin >> w_feets;
    cin >> w_inches;
    total_w_inches = w_inches + ( w_feets * 12 );

    cout << "Enter room length (feet and inches, separated by a space):" << endl;
    cin >> l_feets;
    cin >> l_inches;
    total_l_inches = l_inches + ( l_feets * 12 );


    wid = total_w_inches / tsize;
             if ( total_w_inches % tsize )
        wid++;

    len = total_l_inches / tsize;
    if ( total_l_inches % tsize )
        len++;

    tiles = tiles ( len + wid );

    cout << "Room requires " << ( wid + len ) << " tiles" << endl;

  }
  cout << "Total tiles required is " << tiles << endl;

  cout << "Number of boxes needed is " << bo << endl;
  bo = tiles / 20;

  if ( tiles % 20)
  bo++;

  cout << "There will be " << bo * 20 - tiles << " tiles left" << endl;

 return 0;
}

the red part is what I'm having problem right now i don't know what I'm doing wrong.

If anyone could help me with something that would be great.

Thanks.

The infinite loop is caused by the fact that you never decrement your num_rooms variable. add
<TAB>num_rooms--;
to the end of your while loop.

Your number of tiles issue is located in the following commands:

// I don't know what this is for, you could probably remove this
tiles = tiles ( len + wid );

// the width and length should be multiplied not added.
cout << "Room requires " << ( wid + len ) << " tiles" << endl;

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.