Not really sure why my program isn't running but can someone correct the errors

#include <iostream>
#include <string>
using namespace std;

double FindCost( char woodType, int numPieces,int width, int length,int height);

void main()
{
char woodType;
int numPieces,width,length,height;
double total=0.0,cost;
do
{
cout <<" Enter item";
cin >> woodType;
if (woodType=='T')
{
cout<<"Total cost: $"<< total<< endl;
break;
}

cin >>numPieces;
cin >> width;
cin>>length;
cin>>height;

cost=FindCost(woodType,numPieces,width,length,height);
cout <<"' cost: $"<< cost<<endl;
total+=cost;
}while(woodType!='T');

system("pause");

double FindCost (char woodType,int pieces,int width,int length,int height);

{
double cost;
string name;
cost=(length*width*height)/12.0;
cost=numPieces*cost;
if(woodType=='P')
{
cost=cost*0.89;
name="Pine";
}
else if (woodType=='F')
{
cost=cost*1.09;
name="Fir";
}
else if(woodType=='C')
{
cost=cost*2.26;
name="Cedar";
}
else if(woodType=='M')
{
cost=cost*4.50;
name="Maple";
}
else if(woodType=='O')
{
cost=cost*3.10;
name="Oak";
}
cout << numPieces<<" " << width <<"x" << length << "x" << height << name;

return cost;
}
}
Function main() must always return int
 
void main()
it should be
 
int main()


You have a misplaced closing brace }
The end of main() is missing its closing brace, instead it has ended up somehow right at the very end of the file.


Where you provide the definition of function FindCost(), remove the semicolon at the end of the line.

The variable named numPieces does not exist (but pieces does).
Last edited on
void main() isn't C++.
int main() is C++

Your findcost function is being defined inside main. Don't do that.

double FindCost (char woodType,int pieces,int width,int length,int height); has a semi-colon on the end. It shouldn't be there when you're defining a function; only when declaring a function.

Your code outputs the total cost before you calculate it. That makes no sense.

Topic archived. No new replies allowed.