Need help with C++

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.

#include <iostream>
#include <iomanip>

using namespace std;

const double costPerMileLess100 = 5.0,
costPerMileLess500 = 4.0,
costPerMileOver500 = 3.0;

// 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
}

double calculateVariableCost(double miles)
{
double cost = 50.0; // fixed cost

// 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.

return (0);
}
You're using system without having included <cstdlib>

You've also screwed up this line: return (0;) // program exits with no errors
The semi-colon goes outside the bracket.


The good way to fix this is to stop using system and use something better.

Here are a number of pages explaining why:

http://www.gidnetwork.com/b-61.html
http://www.cplusplus.com/forum/windows/55426/
http://www.cplusplus.com/forum/beginner/1988/

The short answer is don't use system("pause");


"fatal error LNK1120: 1 unresolved external

If your linker didn't tell you which external was unresolved, throw it away and get one that tells you what the problems are.

It's interesting how your calculateVariableCost function goes through a lot of trouble to calculate a cost, and then always returns the value zero.
Last edited on
1>LINK : error LNK2001: unresolved external symbol _mainCRTStartup

That's another part of the error its displaying. Maybe this helps?
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.
Last edited on
Yeah i'm using visual studio 2010, it knows im making a plain win32 project, i just can't see where its going wrong :(
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.
Just realised i didn't attach the code to the project lol i'm so embarrassed :( thanks for your help :)
also, the code for the £ sign is wrong. Do you know what it is?
Topic archived. No new replies allowed.