Made this C++ program and it says this when i try to build it - "fatal error LNK1120: 1 unresolved externals", i'm trying to find the problem but can't seem to locate it. Here's the full programming code. I'll appreciate any help from anyone.
// Argument: number of miles (not always an integer in general case)
// Returns: total cost.
double calculateVariableCost(double miles);
int main (int argc, char * argv[])
{
double miles;
cout<<fixed; /* When floatfield is set to fixed, float values are written
using fixed-point notation, which means the value is represented with
exactly as many digits in the fraction part as specified by the precision
field and with no exponent part. */
cout<<setprecision(2); /* The decimal precision determines the maximum number
of digits to be written on insertion operations to express floating-point values. */
cout<<"Enter the distance in miles: ";
cin>>miles;
if (miles < 0) // display error message if input < 0
cout<<"ERROR: The distance should be a positive value.\n\n";
else
cout<<"The cost of shipment over "<<miles<<" miles is "<<char(163)<<calculateVariableCost(miles)<<endl;
// char(163) is a char code for pound sign
system("pause"); // wait for keypress
return (0;) // program exits with no errors
}
// calculating the cost with different prices per mile
if (miles > 500.0) /* in case miles > 500, the price is
3 pounds for each mile which is over 500 miles */
{
cost += (miles - 500.0) * costPerMileOver500;
miles = 500.0; /* as we calculated the cost of each mile
which is over 500, we have 500 miles remaining */
}
if (miles > 100.0) // the price is the price is 4 pounds for each mile which is over 100 miles
{
cost += (miles - 100.0) * costPerMileLess500;
miles = 100.0; // we have 100 miles remaining
}
cost += miles * costPerMileLess100; // the price of each of the first miles (<=100 miles) is 5 pounds.
Whatever IDE you're using thinks you're trying to build something you're not. If I had to guess, you're using some kind of Visual Studio. Make sure it thinks you're making a plain Win32 Console project.
Your code (aside from those minor whinges I pointed out) is fine. It's all on your IDE. Start a new project, make sure it's plain console, and copy the code in.