The calculation works out correctly when there is an even number of feet for the room, but when I input both feet and inches, I don't know if it is calculating correctly.

Anyway my question is about the math. Particularly the number of tiles required. Did I do this right?

Also, is there a better way of rounding up the double to the nearest int? I want to round it up even if we need 9.1 boxes, since we would then need 10 boxes.

#include<iostream> #include<conio.h> //for getch() using namespace std; //function prototypes int getInfo(); int convertToInches(int, int); int getArea(int, int); double getTiles(int, int); //functions int getInfo(){ int x; cin>>x; return x; } int convertIn(int ft, int in){ int totalIn; ft = ft * 12; totalIn = ft + in; return totalIn; } int getArea(int tw, int tl){ int area = tw * tl; return area; } double getTiles(int tile, int area){ double need = area/(tile*tile); return need; } int main(){ int rooms=0, tile=0, widthFt=0, widthIn=0,lengthFt=0, lengthIn=0; int totWidth=0, totLength=0, area =0, extra =0; double tilesNeeded=0, boxes =0; const int PERBOX = 20; cout<<"Enter number of rooms:"; rooms = getInfo(); cout<<"Enter size of tile in inches:"; tile = getInfo(); for(int i=0; i<rooms; i++){ cout<<"Enter room width (feet and inches, separated by a space):"; cin>>widthFt>>widthIn; cout<<"Enter room length (feet and inches, separated by a space):"; cin>>lengthFt>>lengthIn; totWidth = convertIn(widthFt, widthIn); totLength = convertIn(lengthFt, lengthIn); area = getArea(totWidth, totLength); tilesNeeded = getTiles(tile, area); //test cout<<"\nTotal tiles needed: "<<tilesNeeded<<endl; boxes = tilesNeeded/PERBOX; boxes +=.9; //to round up in case there is a decimal & we need one more box // change number of boxes to int so it's an even number boxes = static_cast<int>(boxes); cout<<"\nNumber of boxes needed: "<<boxes<<endl; extra = (PERBOX*boxes) - tilesNeeded; //test cout<<"\nLeftover tiles: "<<extra<<endl; } getch(); return 0; }

When I input the sample info from the book, it doesn't come out the same as theirs. I was hoping

*they*had it wrong. lol

sample:

rooms: 2

tile size: 12

room width (ft, in): 17 4

room length (ft, in): 9 3

Room requires 180 tiles

room width (ft, in): 11 6

room length (ft, in): 11 9

Room requires 144 tiles

total tiles required: 324

boxes needed: 17

leftover tiles: 16

I cannot get it to compute the same number of tiles required as they have. I'm thinking it has to do with using partial tiles...or my math is just off.