1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
|
#include <iostream>
#include <iomanip>
using namespace std;
float CalculateCost (float Price, float Quantity, float Width, float Height, float Length);
int main()
{
//Declarations
char TypeOfLumber;
float Price;
float Cost;
float Total;
float Width;
float Height;
float Length;
float Quantity;
while(true)
{
cout << "" << endl;
cout << "Enter the type, quantity, width, height and length of the lumber ";
cin >> TypeOfLumber;
if (TypeOfLumber == 'T' || TypeOfLumber == 't')
{
break;
}
cin >> Quantity >> Width >> Height >> Length;
cout << "" << endl;
cout << fixed << setprecision(0) << Quantity << " " << Width << "x" << Height << "x" << Length;
// Switch for type of lumber
switch (TypeOfLumber)
{
case 'P' :
case 'p' :
Price = 0.89f;
cout << " Pine";
break;
case 'F' :
case 'f':
Price = 1.09f;
cout << " Fir";
break;
case 'C' :
case 'c' :
Price = 2.26f;
cout << " Cedar";
break;
case 'M' :
case 'm' :
Price = 4.50f;
cout << " Maple";
break;
case 'O' :
case '0' :
Price = 3.10f;
cout << " Oak";
break;
}
Cost = CalculateCost(Price, Quantity, Width, Height, Length);
cout << ", Cost: $" << fixed << setprecision(2) << Cost << endl;
}
Total += Cost;
cout << "Total cost: $" << Total << endl;
return 0;
}
float CalculateCost (float Price, float Quantity, float Width, float Height, float Length)
{
float CalculateCost;
CalculateCost = Price * (Quantity * Width * Height * Length / 12.0f);
return CalculateCost;
|