diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8855bc9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +# exclude .exe files from being tracked. +*.exe \ No newline at end of file diff --git a/PA02-0914/Project_2.c b/PA02-0914/Project_2.c index 2d19829..8f919e8 100644 --- a/PA02-0914/Project_2.c +++ b/PA02-0914/Project_2.c @@ -36,17 +36,20 @@ void printTopLine(); // main program int main() { - // Define Variables Needed: desiredArea (int) actualArea (int) houseWidth (int) houseDepth (int) - // roofingCost (double) plywoodCost (double) twoByFourCost (double) drywallCost (double) - // totalEstimate (double) + // Define Variables Needed: + //desiredArea (int) actualArea (int) houseWidth (int) houseDepth (int) + // roofingCost (double) plywoodCost (double) twoByFourCost (double) + // drywallCost (double) totalEstimate (double) int desiredArea, actualArea, houseWidth, houseDepth; double roofingCost, plywoodCost, twoByFourCost, drywallCost, totalEstimate; // Print the house cost estimator headline printString("House Cost Estimator"); + // Then print a blank line for formatting. printEndline(); // Print a dividing line, use printCharacters(). + // Literal used since no constants can be created, and no standard found. printCharacters(20, '='); // Print 2 blank lines for formatting nicely. @@ -54,30 +57,48 @@ int main() // Ask user for input about the desired floor sq.ft.-age. desiredArea = promptForInteger("Enter the desired floor square footage: "); + // Then print a blank line for formatting. + printEndline(); - // Calculate the house width(2/3 rounded of the area) (formula: sqrt((desiredSQFT/0.67))) - // then divide by trimmed value, cast to int, and then multiply by trimmed value to get result. - houseWidth = ((findSquareRoot(desiredArea/SIDE_WALL_RATIO)) + BOOSTING_VALUE); + // Calculate the house width(2/3 rounded of the area) + //(formula: sqrt((desiredArea/SIDE_WALL_RATIO))) + // then divide by trimmed value, cast to int, + // and then multiply by trimmed value to get result. + houseWidth = desiredArea/SIDE_WALL_RATIO; + houseWidth = ((findSquareRoot(houseWidth)) + BOOSTING_VALUE); houseWidth = houseWidth / TRIMMING_VALUE; houseWidth = (int) houseWidth * TRIMMING_VALUE; - printEndline(); - // Calculate the house depth(1/3 rounded of the area) (formula: desiredArea/houseWidth) - houseDepth = desiredArea / houseWidth; + + // Calculate the house depth(1/3 rounded of the area) + // (formula: desiredArea/(1/SIDE_WALL_RATIO)) + houseDepth = desiredArea/(1/SIDE_WALL_RATIO); + houseDepth = ((findSquareRoot(houseDepth)) + BOOSTING_VALUE); + houseDepth = houseDepth / TRIMMING_VALUE; + houseDepth = (int) houseDepth * TRIMMING_VALUE; + // Calculate the actual area (houseWidth * houseDepth) actualArea = houseWidth * houseDepth; // Calculate the roofing cost(using the equation provided on BBLearn) roofingCost = actualArea * ROOFING_PRICE; - // Calculate the plywood cost(sums up all the walls and floors of the house.) - plywoodCost = ((houseWidth * HOUSE_HEIGHT) + (houseWidth * HOUSE_HEIGHT)) * PLYWOOD_PRICE; - plywoodCost = plywoodCost + ((houseDepth * HOUSE_HEIGHT) + (houseDepth * HOUSE_HEIGHT)) * PLYWOOD_PRICE; + + // Calculate the plywood cost + // (sums up all the walls and floors of the house.) + plywoodCost = ((houseWidth * HOUSE_HEIGHT) + + (houseWidth * HOUSE_HEIGHT)) * PLYWOOD_PRICE; + plywoodCost = plywoodCost + ((houseDepth * HOUSE_HEIGHT) + + (houseDepth * HOUSE_HEIGHT)) * PLYWOOD_PRICE; plywoodCost = plywoodCost + (houseWidth * houseDepth) * PLYWOOD_PRICE; + // Calculate the 2x4 cost(using the equation provided on BBLearn) twoByFourCost = (NUM_2x4_PER_FOOT * houseWidth); twoByFourCost = twoByFourCost + (NUM_2x4_PER_FOOT * houseDepth); twoByFourCost = twoByFourCost * TWO_BY_FOUR_PRICE; + // Calculate the drywall cost(using the equation provided on BBLearn) - drywallCost = (((houseWidth * HOUSE_HEIGHT)*2) + ((houseDepth * HOUSE_HEIGHT)*2)) * DRYWALL_PRICE; + drywallCost = (((houseWidth * HOUSE_HEIGHT)*2) + + ((houseDepth * HOUSE_HEIGHT)*2)) * DRYWALL_PRICE; + // Calculate the Total Estimate cost(add up using the previous values) totalEstimate = roofingCost + plywoodCost + twoByFourCost + drywallCost; @@ -85,6 +106,7 @@ int main() printEndline(); // Print a dividing line, use the printTopLine(). + // Then print a blank line for formatting. printTopLine(); printEndline(); @@ -103,108 +125,153 @@ int main() printEndline(); // Printed output of the desired area + // Uses functions printCharacter, printStringJustified, + // printIntegerJustified, printLightDividedLine, and printEndline printCharacter(PIPE); - printStringJustified(" Desired Area", DESCRIPTION_WIDTH, "LEFT"); + printCharacter(SPACE); + printStringJustified("Desired Area", DESCRIPTION_WIDTH - 1, "LEFT"); printCharacter(PIPE); - printIntegerJustified(desiredArea, VALUE_WIDTH, "RIGHT"); + printIntegerJustified(desiredArea, VALUE_WIDTH - 1, "RIGHT"); + printCharacter(SPACE); printCharacter(PIPE); - printStringJustified(" sq ft", UNIT_WIDTH, "LEFT"); + printCharacter(SPACE); + printStringJustified("sq ft", UNIT_WIDTH - 1, "LEFT"); printCharacter(PIPE); printEndline(); printLightDividedLine(); printEndline(); // Printed output of the actual area, using the houseWidth * houseDepth + // Uses functions printCharacter, printStringJustified, + // printIntegerJustified, printLightDividedLine, and printEndline printCharacter(PIPE); - printStringJustified(" Actual Area", DESCRIPTION_WIDTH, "LEFT"); + printCharacter(SPACE); + printStringJustified("Actual Area", DESCRIPTION_WIDTH - 1, "LEFT"); printCharacter(PIPE); - printIntegerJustified(actualArea, VALUE_WIDTH, "RIGHT"); + printIntegerJustified(actualArea, VALUE_WIDTH - 1, "RIGHT"); + printCharacter(SPACE); printCharacter(PIPE); - printStringJustified(" sq ft", UNIT_WIDTH, "LEFT"); + printCharacter(SPACE); + printStringJustified("sq ft", UNIT_WIDTH -1, "LEFT"); printCharacter(PIPE); printEndline(); printLightDividedLine(); printEndline(); // Printed output of the house's width + // Uses functions printCharacter, printStringJustified, + // printIntegerJustified, printLightDividedLine, and printEndline printCharacter(PIPE); - printStringJustified(" House Width", DESCRIPTION_WIDTH, "LEFT"); + printCharacter(SPACE); + printStringJustified("House Width", DESCRIPTION_WIDTH - 1, "LEFT"); printCharacter(PIPE); - printIntegerJustified(houseWidth, VALUE_WIDTH, "RIGHT"); + printIntegerJustified(houseWidth, VALUE_WIDTH - 1, "RIGHT"); + printCharacter(SPACE); printCharacter(PIPE); - printStringJustified(" feet", UNIT_WIDTH, "LEFT"); + printCharacter(SPACE); + printStringJustified("feet", UNIT_WIDTH - 1, "LEFT"); printCharacter(PIPE); printEndline(); printLightDividedLine(); printEndline(); // Printed output of the house's depth + // Uses functions printCharacter, printStringJustified, + // printIntegerJustified, printLightDividedLine, and printEndline printCharacter(PIPE); - printStringJustified(" House Depth", DESCRIPTION_WIDTH, "LEFT"); + printCharacter(SPACE); + printStringJustified("House Depth", DESCRIPTION_WIDTH - 1, "LEFT"); printCharacter(PIPE); - printIntegerJustified(houseDepth, VALUE_WIDTH, "RIGHT"); + printIntegerJustified(houseDepth, VALUE_WIDTH - 1, "RIGHT"); + printCharacter(SPACE); printCharacter(PIPE); - printStringJustified(" feet", UNIT_WIDTH, "LEFT"); + printCharacter(SPACE); + printStringJustified("feet", UNIT_WIDTH - 1, "LEFT"); printCharacter(PIPE); printEndline(); printLightDividedLine(); printEndline(); // Printed output of the roofing cost + // Uses functions printCharacter, printStringJustified, + // printIntegerJustified, printLightDividedLine, and printEndline printCharacter(PIPE); - printStringJustified(" Roofing Cost", DESCRIPTION_WIDTH, "LEFT"); + printCharacter(SPACE); + printStringJustified("Roofing Cost", DESCRIPTION_WIDTH - 1, "LEFT"); printCharacter(PIPE); - printDoubleJustified(roofingCost, PRECISION, VALUE_WIDTH, "RIGHT"); + printDoubleJustified(roofingCost, PRECISION, VALUE_WIDTH - 1, "RIGHT"); + printCharacter(SPACE); printCharacter(PIPE); - printStringJustified(" dollars", UNIT_WIDTH, "LEFT"); + printCharacter(SPACE); + printStringJustified("dollars", UNIT_WIDTH - 1, "LEFT"); printCharacter(PIPE); printEndline(); printLightDividedLine(); printEndline(); // Printed output of the plywood cost + // Uses functions printCharacter, printStringJustified, + // printDoubleJustified, printLightDividedLine, and printEndline printCharacter(PIPE); - printStringJustified(" Plywood Cost", DESCRIPTION_WIDTH, "LEFT"); + printCharacter(SPACE); + printStringJustified("Plywood Cost", DESCRIPTION_WIDTH - 1, "LEFT"); printCharacter(PIPE); - printDoubleJustified(plywoodCost, PRECISION, VALUE_WIDTH, "RIGHT"); + printDoubleJustified(plywoodCost, PRECISION, VALUE_WIDTH - 1, "RIGHT"); + printCharacter(SPACE); printCharacter(PIPE); - printStringJustified(" dollars", UNIT_WIDTH, "LEFT"); + printCharacter(SPACE); + printStringJustified("dollars", UNIT_WIDTH - 1, "LEFT"); printCharacter(PIPE); printEndline(); printLightDividedLine(); printEndline(); // Printed output of the 2x4 cost + // Uses functions printCharacter, printStringJustified, + // printDoubleJustified, printLightDividedLine, and printEndline printCharacter(PIPE); - printStringJustified(" 2 X 4 Cost", DESCRIPTION_WIDTH, "LEFT"); + printCharacter(SPACE); + printStringJustified("2 X 4 Cost", DESCRIPTION_WIDTH - 1, "LEFT"); printCharacter(PIPE); - printDoubleJustified(twoByFourCost, PRECISION, VALUE_WIDTH, "RIGHT"); + printDoubleJustified(twoByFourCost, PRECISION, VALUE_WIDTH - 1, "RIGHT"); + printCharacter(SPACE); printCharacter(PIPE); - printStringJustified(" dollars", UNIT_WIDTH, "LEFT"); + printCharacter(SPACE); + printStringJustified("dollars", UNIT_WIDTH - 1, "LEFT"); printCharacter(PIPE); printEndline(); printLightDividedLine(); printEndline(); // Printed output of the drywall cost + // Uses functions printCharacter, printStringJustified, + // printDoubleJustified, printLightDividedLine, and printEndline printCharacter(PIPE); - printStringJustified(" Drywall Cost", DESCRIPTION_WIDTH, "LEFT"); + printCharacter(SPACE); + printStringJustified("Drywall Cost", DESCRIPTION_WIDTH - 1, "LEFT"); printCharacter(PIPE); - printDoubleJustified(drywallCost, PRECISION, VALUE_WIDTH, "RIGHT"); + printDoubleJustified(drywallCost, PRECISION, VALUE_WIDTH - 1, "RIGHT"); + printCharacter(SPACE); printCharacter(PIPE); - printStringJustified(" dollars", UNIT_WIDTH, "LEFT"); + printCharacter(SPACE); + printStringJustified("dollars", UNIT_WIDTH - 1, "LEFT"); printCharacter(PIPE); printEndline(); printLightDividedLine(); printEndline(); // Printed output of the Total Estimate + // Uses functions printCharacter, printStringJustified, + // printDoubleJustified, printLightDividedLine, and printEndline printCharacter(PIPE); - printStringJustified(" Total Estimate", DESCRIPTION_WIDTH, "LEFT"); + printCharacter(SPACE); + printStringJustified("Total Estimate", DESCRIPTION_WIDTH - 1, "LEFT"); printCharacter(PIPE); - printDoubleJustified(totalEstimate, PRECISION, VALUE_WIDTH, "RIGHT"); + printDoubleJustified(totalEstimate, PRECISION, VALUE_WIDTH - 1, "RIGHT"); + printCharacter(SPACE); printCharacter(PIPE); - printStringJustified(" dollars", UNIT_WIDTH, "LEFT"); + printCharacter(SPACE); + printStringJustified("dollars", UNIT_WIDTH - 1, "LEFT"); printCharacter(PIPE); printEndline(); printLightDividedLine(); @@ -330,4 +397,3 @@ void printTopLine() // function: printCharacters printCharacters( TABLE_WIDTH, THIN_LINE ); } -