In: Computer Science
COVID -19 changed our lifestyles in so many different ways. Due to safety concerns, suddenly everyone wants to wear face masks. However, as the suppliers fail to keep up with the demand, one option is to use homemade facemasks.
According to the crafting experts, one adult mask requires two 9" x 6" pieces of tight-weave cotton and two 7" pieces of elastic. The elastic only sold in full yards.
Write a program that reads the length (in yards) and width (in inches) of a piece of fabric from the user and displays the following.
For example,
Notes:
Here we need to take length in yards and width in inches
since one mask requires two 9X6 pieces of weaven cotton and two 7 inches pieces of elastic
so inorder to get total no of masks that can be made from the given cotton is
for the given test case
that is 1 yard and 44 inches
(36*44)/(2*9*6)=14.66
but we require maximum so we will take floor and round it to 14
so as we know that a mask require 2 elastic of 7 inches
so 14 masks will require 14*2*7 inches converting it to yard
(14*2*7)/36 and take ceil of it
6 yards of elastic required
Below is the code Attached with Output attached
#include<bits/stdc++.h>
using namespace std;
int main()
{
int cloth,w;
cout<<"Enter length in yards\n";
cin>>cloth;
int c=cloth;
cout<<"Enter the width in inches\n";
cin>>w;
cloth*=36;//converting to inches
float z=2*9*6;
float l=(float)(cloth*w)/z;
int p=floor(l);
cout<<c<<" yard cloth will yeild "<<p<<"facemasks"<<"\n";
int k=p*14;
float elast=(float)k/36;
cout<<"You will require "<<ceil(elast)<<"elastic"<<"\n";
return 0;
}