I am trying to write a program using functions. I am having trouble with two of the functions. one in question is calculate_drywall. Which is passed two values in feet for length and width and returns the various size drywall sheets for the room. The sheets come in 4x 8, 10, 12, 14, 16. I am using a void with reference parameters. The second function I am having trouble with is calculate material which is passed the total number of sheets for the building and returns the amount of screws and mud required. Where I am confused is the drywall function returns the sheets for each room then in materials it is taking in the building total. Should I do something in main? Any help would be appreciated.
Here is what I have so far
#include<iostream>
#include<fstream>
#include<iomanip>
#include<string>
#include<cmath>
#include<math.h>
using namespace std;
void get_data(double& val1, double& val2, bool& error, ifstream&);
double convert_to_feet(double val);
void calculate_drywall(double& tot_8ft, double& tot_10ft, double& tot_12ft, double& tot_14ft, double& tot_16ft, double& perimeter, double& in_feet1, double& in_feet2);
void calculate_material(double& tot_8ft, double& tot_10ft, double& tot_12ft, double& tot_14ft, double& tot_16ft, double& mud, double& screws, double& sqr_ft);
void print_output(double room_num, double in_feet1, double in_feet2, bool error, ofstream&, double perimeter, double tot_16ft, double sqr_ft);
int main()
{
double val1, val2, room_num = 0, in_feet1, in_feet2, perimeter = 0;
double tot_8ft, tot_10ft, tot_12ft, tot_14ft, tot_16ft = 0;
double mud, screws, sqr_ft = 0;
bool error;
string proj_title;
ifstream infile;
ofstream outfile;
infile.open("proj_info.txt");
outfile.open("supplies.txt");
getline(infile, proj_title);
get_data(val1, val2, error, infile);
while (infile)
{
room_num++;
in_feet1 = convert_to_feet(val1);
in_feet2 = convert_to_feet(val2);
calculate_drywall(tot_8ft, tot_10ft, tot_12ft, tot_14ft, tot_16ft, in_feet1, in_feet2, perimeter);
get_data(val1, val2, error, infile);
}
calculate_material(tot_16ft, tot_14ft, tot_12ft, tot_10ft, tot_8ft, mud, screws, sqr_ft);
}
void get_data(double& val1, double& val2, bool& error, ifstream& in)
{
in >> val1 >> val2;
if (val1 <= 0 || val2 <= 0)
error = 0;
else
error = 1;
}
double convert_to_feet(double val)
{
double in_feet;
in_feet = val * 3.28;
return in_feet;
}
void calculate_drywall(double& tot_8ft, double& tot_10ft,
double& tot_12ft, double& tot_14ft,
double& tot_16ft, double& in_feet1,
double& in_feet2, double& perimeter)
{
perimeter = 2 * (in_feet1 + in_feet2);
if (perimeter >= 16)
tot_16ft = (perimeter / 16) * 2;
else
if (perimeter <= 16 && perimeter >= 14)
tot_14ft = (perimeter / 14) * 2;
else
if (perimeter <= 14 && perimeter >= 12)
tot_12ft = (perimeter / 12) * 2;
else
if (perimeter <= 12 && perimeter >= 10)
tot_10ft = (perimeter / 10) * 2;
else
tot_8ft = (perimeter / 8) * 2;
}
void calculate_material(double& tot_8ft, double& tot_10ft, double& tot_12ft, double& tot_14ft, double& tot_16ft, double& mud, double& screws, double& sqr_ft)
{
sqr_ft = (tot_16ft * (16 * 4)) + (tot_14ft * (14 * 4)) + (tot_12ft * (12 * 4)) + (tot_10ft * (10 * 4)) + (tot_8ft * (8 * 4));
}
void print_output(double room_num, double in_feet1, double in_feet2, bool error, ofstream& out, double perimeter, double tot_16ft, double sqr_ft)
{
out << ceil (tot_16ft) << sqr_ft << endl;
}