219k views
5 votes
Using functions,

In C++

code a function that calculates how many tiles are needed to cover a floor.

The inputs to the function are height in feet, width in feet and tile size in inches.

The output of the function is the number of tiles.

Consider how the tiles are laid out, you have whole tiles until you get the last tile where mostly like the last tile won't fit, so you need a partial tile and once a tile is cut to fit a space it can't be reused.

The function is then called in the int main() body.

examples for input/output - Please verify.

for input:

height in feet: 1

width in feet: 1

tile size in inches: 8

the output should = 4

for input:

height in feet: 10.5

width in feet: 1.42

tile size in inches: 8

the output should = 48

1 Answer

3 votes

Answer:

See explaination

Step-by-step explanation:

#include <iostream>

using namespace std;

int main()

{

double h, w;

int s, a, b;

cout<<"height in feet: ";

cin>>h;

cout<<"width in feet: " ;

cin>>w;

cout<<"tile size in inches:";

cin>>s;

int height = h*12;

if(height%s==0)

a = height/s;

else

a = height/s + 1;

int width = w*12;

if(width%s==0)

b = width/s;

else

b = width/s + 1;

cout<<"Number of tiles: "<<a*b;

}

User Nullstellensatz
by
4.5k points