Hey all, could someone help me understand what I am doing wrong here? When I try to build this code I get a response: "fatal error LNK1169: one or more multiply defined symbols found" and "_main already defined in idealLength.obj" how do I make this code work?
#include <iostream> // required for cout
#include <cmath> // required for sqrt
using namespace std;
class Tank // set the class Tank which will classify the values of the tank
{
public:
double heightPr;
double heightPy; // The variables of class Tank defined here
double length;
double width;
double volume;
double surfaceAreaPr;
double surfaceAreaPy;
double costPerSMPr;
double costPerSMPy;
double costPr;
double costPy;
double totalCost;
Tank() // Declare the values of some variables from within the Tank class
{
heightPr = 10;
costPerSMPr = 300;
costPerSMPy = 400;
}
};
int main()
{
Tank Test; //call Tank class under name Test
double idealLength, idealTotalCost(999999999999);
cout << "Enter tank volume >>> "; // get the user to input the value of initial volume
cin >> Test.volume;
for(int k=2; k<=40; k=1)
{
Test.length = k;
Test.width = Test.volume/(Test.length * Test.heightPr + .333333333333 * (Test.length/2) * Test.length); //equations that solve for the width and surface area of the two parts to the tank
Test.surfaceAreaPr = (Test.length * Test.width) + (Test.heightPr * Test.length * 2) + (Test.heightPr * Test.width * 2);
Test.surfaceAreaPy = sqrt((Test.length/2) * (Test.length/2) + (Test.length/2) * (Test.length/2)) * Test.width + sqrt((Test.width/2) * (Test.width/2) + (Test.length/2) * (Test.length/2)) * Test.length;
Test.totalCost = Test.costPr + Test.costPy; // putting the two parts together to generate the final cost
if (idealTotalCost > Test.totalCost)
{
idealTotalCost = Test.totalCost;
idealLength = Test.length;
}
}
cout << "The optimal length is " << idealLength << " meters.";
cout << "The cost at this length is " << idealTotalCost << ".";
return 0;
Found a few mistakes. You can't initialize variables in a class, unless they are const, so I removed them. Your for(int k=2; k<=40; k=1) should be for(int k=2; k<=40; k++), and I added << endl at both cout's on the bottom of the program, to put each on a separate line. Here is your code that I was able to compile and run using MS Visual C++ 2008 Express Edition. Of course, I don't know if your math is correct or not, but I'm guessing it is.