help with code



#include <string>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cctype>

using namespace std;


enum Species { LoblollyPine, WhitePine, RedPine, WhiteOak, RedOak, OtherOak};



// funtion prototypes

int getTreeNo();
int getSpeciesCode();
float getDbh();
int getTotHt();
float calTotVol(double b0, double b1, float dbh, int totalHt);

int main()
{
// Variables

int treeNo;
int speciesCode;
string speciesDesc[6];
float dbh;
int totalHt;
float totalVol;
int Species[6];
double b0[6] = {1.2446, 0.000, 2.0822, .7316, 1.6378, .7554};
double b1[6] = {.002165, .002364, .002046, .001951, .002032, .002174};

treeNo = getTreeNo();
speciesCode = getSpeciesCode();
dbh = getDbh();
totalHt = getTotHt();
totalVol = calTotVol(b0[0],b1[0],dbh,totalHt);


// major loop
while (treeNo < 999)
{
getTreeNo();
getSpeciesCode();
getDbh();
getTotHt();
calTotVol(b0[6],b1[6],dbh,totalHt);
}

system("pause");
return 0;
}

int getTreeNo(int)
{
int treeNo;
do
{
cout <<"Please input the tree number."<<endl;
cin>> treeNo;
if (treeNo < 0 || treeNo > 200)
cout<<" Tree number must be greater than 0 and less than 200. "<<endl;
}while (treeNo <= 999);

return treeNo;
}

int getSpeciesCode()
{
int speciesCode;
string speciesDesc;
double b0[6];
double b1[6];
bool inputOk;
inputOk = true;
do
{
cout<<"Enter the species code: "<<endl;
cin>>speciesCode;
if (speciesCode == 11)
{
speciesDesc = LoblollyPine;
b0[0] = 1.2446;
b1[0] = .002165;
inputOk = true;
}
else
if(speciesCode == 12)
{
speciesDesc = WhitePine;
b0[1] = 0.000;
b1[1] = .002364;
inputOk = true;
}
else
if(speciesCode == 13)
{
speciesDesc = RedPine;
b0[2] = 2.0822;
b1[2] = .002046;
inputOk = true;
}
else
if(speciesCode == 21)
{
speciesDesc = WhiteOak;
b0[3] = .7316;
b1[3] =.001951;
inputOk = true;
}
else
if(speciesCode == 22)
{
speciesDesc = RedOak;
b0[4] = 1.6378;
b1[4] = .002032;
inputOk = true;
}
else
if(speciesCode == 23)
{
speciesDesc = OtherOak;
b0[5] = .7554;
b1[5] = .002174;
inputOk = true;
}



}while (inputOk);

return speciesCode;
}

float getDbh()
{
float dbh;
cout<<"Please enter a value between 5.0 and 50.6."<<endl;
cin>> dbh;
if (dbh < 5.0 || dbh > 50.6)
cout<<"Incorrect value entered please try again."<<endl;
return dbh;
}

int getTotHt()
{
int totalHt;
cout<< "Please enter the total height of the tree."<<endl;
cout<<"The value must be between 24 qnd 160."<<endl;
cin>> totalHt;
if (totalHt < 24 || totalHt > 160)
cout<<"Please enter a value within the parameters."<<endl;
return totalHt;
}

float calTotVol(double b0[6], double b1[6], float dbh, int totalHt)
{
float totalVol;
totalVol = (b0[6] + b1[6]) * pow(dbh,2) * (totalHt);
return totalVol;
}



I am getting the following errors when attempting to complie


Warning 1 warning C4101: 'Species' : unreferenced local variable c:\users\big yo\desktop\c++\cplusplusfinal\cplusplusfinal\cplusplusfinal.cpp 36
Warning 2 warning C4244: '=' : conversion from 'double' to 'float', possible loss of data c:\users\big yo\desktop\c++\cplusplusfinal\cplusplusfinal\cplusplusfinal.cpp 166
Warning 3 warning C4700: uninitialized local variable 'b1' used c:\users\big yo\desktop\c++\cplusplusfinal\cplusplusfinal\cplusplusfinal.cpp 54
Warning 4 warning C4700: uninitialized local variable 'b0' used c:\users\big yo\desktop\c++\cplusplusfinal\cplusplusfinal\cplusplusfinal.cpp 54
Error 5 error LNK2019: unresolved external symbol "float __cdecl calTotVol(double,double,float,int)" (?calTotVol@@YAMNNMH@Z) referenced in function _main C:\Users\Big Yo\Desktop\C++\CPlusPlusFinal\CPlusPlusFinal\CPlusPlusFinal.obj
Error 6 error LNK2019: unresolved external symbol "int __cdecl getTreeNo(void)" (?getTreeNo@@YAHXZ) referenced in function _main C:\Users\Big Yo\Desktop\C++\CPlusPlusFinal\CPlusPlusFinal\CPlusPlusFinal.obj
Error 7 error LNK1120: 2 unresolved externals C:\Users\Big Yo\Desktop\C++\CPlusPlusFinal\Debug\CPlusPlusFinal.exe 1


The line numbers in your diagnostics don't line up with the code you posted.

PLEASE USE CODE TAGS (the <> formatting button) when posting code.

Line 32 warning - Species you declared this variable, but never referenced it.
Line 162 warning - You're losing significance because you're calculating doubles and trying to store the result in a float.

Line 50 warning - uninitialized variable b0. You're trying to pass b0[6]. Your array only contains elements 0-5.
Line 50 warning - uninitialized variable b1. Same problem.

unresolved external symbol "float __cdecl calTotVol(double,double,float,int)" - Your forward declarations and your implementation do not agree. Your prototype declares b0 and b1 as simple variables. Your implementation arguments are arrays.

unresolved external symbol "int __cdecl getTreeNo(void)" - again your prototype and your implementation don't agreee. Your prototype takes no arguments. Your implementation expects an int,


#include <string>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cctype>

using namespace std;


enum Species { LoblollyPine, WhitePine, RedPine, WhiteOak, RedOak, OtherOak};



// funtion prototypes

int getTreeNo();
int getSpeciesCode();
float getDbh();
int getTotHt();
float calTotVol(double b0, double b1, float dbh, int totalHt);

int main()
{
// Variables

int treeNo;
int speciesCode;
string speciesDesc[6];
float dbh;
int totalHt;
float totalVol;
int Species[6];
double b0[6] = {1.2446, 0.000, 2.0822, .7316, 1.6378, .7554};
double b1[6] = {.002165, .002364, .002046, .001951, .002032, .002174};

treeNo = getTreeNo();
speciesCode = getSpeciesCode();
dbh = getDbh();
totalHt = getTotHt();
totalVol = calTotVol(b0[0],b1[0],dbh,totalHt);


// major loop
while (treeNo < 999)
{
getTreeNo();
getSpeciesCode();
getDbh();
getTotHt();
calTotVol(b0[6],b1[6],dbh,totalHt);
}

system("pause");
return 0;
}

int getTreeNo(int)
{
int treeNo;
do
{
cout <<"Please input the tree number."<<endl;
cin>> treeNo;
if (treeNo < 0 || treeNo > 200)
cout<<" Tree number must be greater than 0 and less than 200. "<<endl;
}while (treeNo <= 999);

return treeNo;
}

int getSpeciesCode()
{
int speciesCode;
string speciesDesc;
double b0[6];
double b1[6];
bool inputOk;
inputOk = true;
do
{
cout<<"Enter the species code: "<<endl;
cin>>speciesCode;
if (speciesCode == 11)
{
speciesDesc = LoblollyPine;
b0[0] = 1.2446;
b1[0] = .002165;
inputOk = true;
}
else
if(speciesCode == 12)
{
speciesDesc = WhitePine;
b0[1] = 0.000;
b1[1] = .002364;
inputOk = true;
}
else
if(speciesCode == 13)
{
speciesDesc = RedPine;
b0[2] = 2.0822;
b1[2] = .002046;
inputOk = true;
}
else
if(speciesCode == 21)
{
speciesDesc = WhiteOak;
b0[3] = .7316;
b1[3] =.001951;
inputOk = true;
}
else
if(speciesCode == 22)
{
speciesDesc = RedOak;
b0[4] = 1.6378;
b1[4] = .002032;
inputOk = true;
}
else
if(speciesCode == 23)
{
speciesDesc = OtherOak;
b0[5] = .7554;
b1[5] = .002174;
inputOk = true;
}



}while (inputOk);

return speciesCode;
}

float getDbh()
{
float dbh;
cout<<"Please enter a value between 5.0 and 50.6."<<endl;
cin>> dbh;
if (dbh < 5.0 || dbh > 50.6)
cout<<"Incorrect value entered please try again."<<endl;
return dbh;
}

int getTotHt()
{
int totalHt;
cout<< "Please enter the total height of the tree."<<endl;
cout<<"The value must be between 24 qnd 160."<<endl;
cin>> totalHt;
if (totalHt < 24 || totalHt > 160)
cout<<"Please enter a value within the parameters."<<endl;
return totalHt;
}

float calTotVol(double b0[6], double b1[6], float dbh, int totalHt)
{
float totalVol;
totalVol = (b0[6] + b1[6]) * pow(dbh,2) * (totalHt);
return totalVol;
}



Errors
Warning 1 warning C4101: 'Species' : unreferenced local variable c:\users\big yo\desktop\c++\cplusplusfinal\cplusplusfinal\cplusplusfinal.cpp 32
Warning 2 warning C4244: '=' : conversion from 'double' to 'float', possible loss of data c:\users\big yo\desktop\c++\cplusplusfinal\cplusplusfinal\cplusplusfinal.cpp 162
Warning 3 warning C4700: uninitialized local variable 'b1' used c:\users\big yo\desktop\c++\cplusplusfinal\cplusplusfinal\cplusplusfinal.cpp 50
Warning 4 warning C4700: uninitialized local variable 'b0' used c:\users\big yo\desktop\c++\cplusplusfinal\cplusplusfinal\cplusplusfinal.cpp 50
Error 5 error LNK2019: unresolved external symbol "float __cdecl calTotVol(double,double,float,int)" (?calTotVol@@YAMNNMH@Z) referenced in function _main C:\Users\Big Yo\Desktop\C++\CPlusPlusFinal\CPlusPlusFinal\CPlusPlusFinal.obj
Error 6 error LNK2019: unresolved external symbol "int __cdecl getTreeNo(void)" (?getTreeNo@@YAHXZ) referenced in function _main C:\Users\Big Yo\Desktop\C++\CPlusPlusFinal\CPlusPlusFinal\CPlusPlusFinal.obj
Error 7 error LNK1120: 2 unresolved externals C:\Users\Big Yo\Desktop\C++\CPlusPlusFinal\Debug\CPlusPlusFinal.exe 1



I already pointed out what your errors are.

And PLEASE LEARN TO USE CODE TAGS. You have been asked once already.
OP, please, grow up. You just said it wont compile and want us to do your homeworks? Not the way to study. I hope no one else will answer to this topic unless the OP becomes more polite and gives some excuses.

Expecting a reply that doesnt include code and hopefully includes a Thank You directed to AbstractionAnon who gave you all the answers - or at least step-by-step questions.

Thanks, Not-Paid-To-Help-Guy.
EssGeEich not sure who you aiming at in your comment however I was asking for help everything I posted was my work as wrong as it may have been. You or no one else has to post anything if you are going to come off like that. I am just trying to get some help and understand a little better. So you have a nice day and if you see anything else I post kindly keep going.
...Seeing the Report button pressed...

I don't think I have offended anyone in any way.
burnout1974 wrote:
EssGeEich not sure who you aiming at in your comment

I'm sure you know who my comment was aiming at - Otherwise you didn't assume I was talking to you - And there's no one else besides me, you and AbstractionAnon on this topic.
burnout1974 wrote:
I was asking for help everything I posted was my work as wrong as it may have been.

We are not mind readers. Anyways, even after AbstractionAnon gave you (for the third time) the right answer, you rudely doubleposted the code and the errors, this time leaving away your "I can't compile this" comment.
burnout1974 wrote:
I am just trying to get some help and understand a little better.

If this last statement was true, then you should have also written something like "Do you know what happened, so I can avoid these problems later?".
burnout1974 wrote:
So you have a nice day and if you see anything else I post kindly keep going.

Just because you tought my intention was to flame this doesn't mean I cannot be of any help to you - Also because I recognized what the problem was and what the solution was - Even after reading the answer.

Making you notice again we're not paid, we don't pay and neither do you - This is a volunteer thing. The answers come from people who want to give an answer.

Giving you a proof I can be of help to you, and quoting AbstractionAnon:

AbstractionAnon wrote:
Your forward declarations and your implementation do not agree

You may not know what a Forward Declaration/Implementation is, Yeah?
Well, Just by reading at your comments I know you DO know something about those:

1
2
3
4
5
6
7
// funtion prototypes

int getTreeNo();
int getSpeciesCode();
float getDbh();
int getTotHt();
float calTotVol(double b0, double b1, float dbh, int totalHt);

These are the Forward Declarations, also called Prototypes as you commented over them.

1
2
3
4
5
6
7
8
9
10
int getTotHt()
{
int totalHt;
cout<< "Please enter the total height of the tree."<<endl;
cout<<"The value must be between 24 qnd 160."<<endl;
cin>> totalHt;
if (totalHt < 24 || totalHt > 160)
cout<<"Please enter a value within the parameters."<<endl;
return totalHt;
}

This is getTotHt's implementation.

The errors are about calTotVol and getTreeNo.
Let's see their Prototypes and Implementations, beginning with calTotVol:

1
2
3
4
5
6
7
8
9
//calTotVol's prototype
float calTotVol(double b0, double b1, float dbh, int totalHt);
// its Implementation
float calTotVol(double b0[6], double b1[6], float dbh, int totalHt)
{
float totalVol;
totalVol = (b0[6] + b1[6]) * pow(dbh,2) * (totalHt);
return totalVol;
}

You see what's different? In your prototype you use double b0, double b1 where in your implementation you use double b0[6], double b1[6]. That's all. Anyways you will have a logic/bad memory access error.
But I'll let you figure that out by yourself unless you re-post asking why the results are completely wrong or why the memory you are accessing is bad.
About getTreeNo:
1
2
3
4
// Prototype:
int getTreeNo(void);
// Implementation:
int getTreeNo(int) { /*...*/ }

You see their difference? You are using an int right there you should substitute with a void - Even because you're not using that parameter.

Have fun, "Big Yo".
Topic archived. No new replies allowed.