:?: Hi i am in my first C++ class and have already written two simple C++ programs. Im working on another using functions.
I have to write 3 functions to calculate the area, cost, and retail price for wooden boxes and a main function to have the user input information for the program and output the results.
main - prompts user for the type and dimensions of the box. I am also supposed to print out the money values with currency notation i used #include <iomanip>
here is what i have. I am still getting 8 errors and 4 warnings.
// David Shaw
// Lab 3 - Functions
// 02/18/05
#include <iostream>
#include <iomanip>
using namespace std;
float boxSurfaceArea (float, float, float);
float boxCost (int, float);
float boxPrice (int, float, float);
int main()
{
// variables
int type;
float length;
float width;
float height;
float surfaceArea;
float cost;
float price;
do
{
// User input
cout<<"Enter a number, (1, 2, 3, or 4) to select a boxType.\n " << endl;
cin>>type;
}
switch ( type )
{
case 1:
cout<<"Enter the length: ";
cin>>length;
cout<<"Enter the width: ";
cin>>width;
cout<<"Enter the height:";
cin>>height;
cout<<"Cost to produce the box is $"<<cost<<endl;
cout<<"Price of the box is $"<<price<<endl;
cout<<"The Area of the box is" << surfaceArea << "sq. inches"<< endl;
break;
case 2:
cout<<"Enter the length: ";
cin>>length;
cout<<"Enter the width: ";
cin>>width;
cout<<"Enter the height:";
cin>>height;
cout<<"Cost to produce the box is $"<<cost<<endl;
cout<<"Price of the box is $"<<price<<endl;
cout<<"The Area of the box is" << surfaceArea << "sq. inches"<< endl;
break;
case 3:
cout<<"Enter the length: ";
cin>>length;
cout<<"Enter the width: ";
cin>>width;
cout<<"Enter the height:";
cin>>height;
cout<<"Cost to produce the box is $"<<cost<<endl;
cout<<"Price of the box is $"<<price<<endl;
cout<<"The Area of the box is" << surfaceArea << "sq. inches"<< endl;
break;
case 4:
cout<<"Enter the length: ";
cin>>length;
cout<<"Enter the width: ";
cin>>width;
cout<<"Enter the height:";
cin>>height;
cout<<"Cost to produce the box is $"<<cost<<endl;
cout<<"Price of the box is $"<<price<<endl;
cout<<"The Area of the box is" << surfaceArea << "sq. inches"<< endl;
break;
}
while (type != 0);
return 0;
}
// David Shaw
// Lab 3 - boxSurfaceArea Function
float boxSurfaceArea(float length, float width, float height) //function for area of box.
{
float surfaceArea = 2 * ( (length * width)
+ (width * height)
+ (length * height) );
return surfaceArea;
}
// David Shaw
// Lab 3 - boxPrice Function
float boxPrice (int type, float area, float cost) //Function prototype
{
switch (type) {
case 1:
price = (cost + (.25 * area));
break;
case 2:
price = (.50 * area) + 5.25;
break;
case 3:
price = cost + (.36 * area) + 7.50;
break;
case 4:
price = cost + (.32 * area) + 6.25;
break;
while (type != 0)
}
return price;
}
// David Shaw
// Lab 3 - boxCost Function
float boxCost (int type, float area)
{
float cost = 0;
switch (type)
{
case 1:
cost = (.11 * area)//Wood cost
+ (.09 * area) //Labor cost
+ (2.25); //Hardware cost
break;
case 2:
cost = (.13 * area)//Wood cost
+ (.11 * area) //Labor cost
+ (3.15); //Hardware cost
break;
case 3:
cost = (.14 * area)//Wood cost
+ (.26 * area) //Labor cost
+ (4.00); //Hardware cost
break;
case 4:
cost = (.17 * area)//Wood cost
+ (.22 * area) //Labor cost
+ (4.95);//Hardware cost
break;
}
while (type != 0)
return cost;
}
Any help would be greatly appreciated.