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 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
|
//This program calculates the cost of lumber
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
double boardFeet (double, double, double);
string getType (char);
double getPrice (char, double);
double price;
int main (){
char type = ' ';
double width = 0.0, height= 0.0, length = 0.0;
int quantity = 0;
double boardFt = 0.0;
string typeWood = " ";
double subTotal = 0.0;
double total = 0.0;
cout << "Lumber Calculator" << endl << endl << "Available type codes: ""P"" for pine , ""F"" for fir, ""C"" for cedar, ""M"" for maple, \n and ""O"" for oak. Press ""T"" for total." << endl
<< "Use type quantity width height length format. (i.e. P 10 2 4 8)" << endl << endl;
cout << "Enter first item: ";
cin >> type >> quantity >> width >> height >> length;
if (type != 'T')
while (type != 'T') {
boardFt = boardFeet (width, height, length);
typeWood = getType (type);
subTotal = getPrice (type, boardFt);
total += subTotal;
cout << quantity << " " << width << "x" << height << "x" << length << " " << typeWood << setprecision(2) << ", Costs: $" << subTotal << endl;
cout << "Enter item: ";
cin >> type >> quantity >> width >> height >> length;}
else
cout << "Total cost: $" << total << endl;
system("pause");
return 0;
}
double boardFeet (double width, double height, double length){
double boardFts = (( width * height * length )/ 12.0);
return boardFts;
}
double getPrice (char type, double boardFt)
{
double price;
switch (toupper(type))
{
case 'P':
return price = boardFt * 0.89;
break;
case 'F':
return price = boardFt * 1.09;
break;
case 'C':
return price = boardFt * 2.26;
break;
case 'M':
return price = boardFt * 4.50;
break;
case 'O':
return price = boardFt * 3.10;
break;
}
return 0;
}
string getType (char type)
{
string woodType;
switch (toupper(type))
{
case 'P':
return woodType = "Pine";
break;
case 'F':
return woodType = "Fir";
break;
case 'C':
return woodType = "Cedar";
break;
case 'M':
return woodType = "Maple";
break;
case 'O':
return woodType = "Oak";
break;
default: 'T';
}
return "T";
}
|