错误LNK2019:未解析的外部符号“double __cdecl calculateRetail(double,double)”

时间:2014-03-07 03:41:54

标签: c++ visual-studio function lnk2019

我收到此错误: error LNK2019: unresolved external symbol "double __cdecl calculateRetail(double,double)" (?calculateRetail@@YANNN@Z) referenced in function _main 1>c:\users\100236744\documents\visual studio 2010\Projects\Item sales price calculator\Debug\Item sales price calculator.exe : fatal error LNK1120: 1 unresolved externals

我对c ++很新。

// FILE: Price markup calculator.cpp
// PROGRAMMER: Karolina Sabat   CPSC 1103   Section: S11
// Program which calculates the retail cost of an item based on wholesale cost and mark up percentage. 
// Calculates the total interest paid based on the annual interest rate.

#include <iostream>         // For cin, cout
#include <iomanip>          // For setw, setprecision
using namespace std;

// FUNCTION PROTOTYPES
void getData (double &, double &);          // Receives USER INPUT - Wholesale cost & percentage markup
double calculateRetail(double, double);     // Calculates retail price
void Display (double, double, double);      // Displays results: Wholesale cost, markup percentage, retail price

int main ()
{

// VARIABLES
double  wholesale_cost = 0;                 // Wholesale item cost - USER INPUT
double  markup_percent = 0;                 // Markup percentage
double  retail_price = 0;               // Calculated retail cost

// FUNCTION CALL 1: Wholesale cost - USER INPUT
getData(wholesale_cost, markup_percent);
// FUNCTION CALL 2: Retail price - CALCULATION
calculateRetail(wholesale_cost, markup_percent); 
// FUNCTION CALL 3: Display Wholesale price, markup percentage, retail price - OUTPUT
Display(wholesale_cost, markup_percent, retail_price);
// PROGRAM MADE BY - OUTPUT
cout << endl << endl;
cout << " Written by: Karolina Sabat - CPSC 1103 - Section: S11" << endl << endl;
 return 0;
 }

// FUNCTION 1: GetData
void getData (double &wholesale_c, double &markup_p)
{
// Wholesale cost - USER INPUT
cout << " Please enter the item's wholesale cost: $ ";
cin >> wholesale_c;
// Wholesale cost - INVALID ENTRY 
while (wholesale_c < 0)
{
    cout << endl;
    cout << " Please enter a wholesale cost greater than 0." << endl;
    cout << " Item's wholesale cost: $ ";
    // Will clear characters
    cin.clear();
    cin.ignore(numeric_limits<streamsize>::max(), '\n');
    cin >> wholesale_c;
}
// Wholesalecost - VALID
// Markup percentage - USER INPUT
cout << "Please enter the markup percentage: % " ;
cin >> markup_p;
// Markup percentage - INVALID
while (markup_p < 0) 
{
    cout << " ERROR: INVALID INPUT." << endl;
    cout << " Please enter a markup percentage greater than 0." << endl;
    cout << " Markup percentage: % ";
    // Will clear characters
    cin.clear();
    cin.ignore(numeric_limits<streamsize>::max(), '\n');
    cin >> markup_p;
}
}

// FUNCTION 2: CalculateRetail
double CalculateRetail (double wholesale_c, double markup_p)
{
// VARIABLES
double markup_amount;
double retail_price;
// CALCULATIONS
markup_amount = (wholesale_c * markup_p) / 100;
// Markup amount
retail_price = wholesale_c + markup_amount;
return retail_price;
}

// FUNCTION 3: Display
void Display (double wholesale_cost, double markup_percent, double retail_price)
{
// Title - OUTPUT
cout << endl;
cout << " WHOLESALE COST: " << setw(10) << "PRICE MARKUP %: " << setw(10) << "RETAIL PRICE" << endl;
cout << " ________________________________________________________________________________" << endl;
cout << endl;
// NUMBER FORMATING
cout << setprecision(2) << fixed << showpoint;
// Results - OUTPUT
cout << " " << wholesale_cost << setw(10) << markup_percent << setw(10) << retail_price;
}

3 个答案:

答案 0 :(得分:2)

您遇到此问题是因为您将函数的原型编写为:

double calculateRetail(double, double);

但是当你实现这个功能时,你写道:

double CalculateRetail (double wholesale_c, double markup_p)

C和C ++区分大小写,因此它看不到CalculateRetail和calculateRetail。您可能打算将CalculateRetail写为calculateRetail。

答案 1 :(得分:2)

calculateRetail delacred and used。 CalculateRetail已定义。 ...... c!= C

答案 2 :(得分:1)

double calculateRetail(double, double);

double CalculateRetail (double wholesale_c, double markup_p)

您的函数定义与其原型不完全匹配。如果您将定义的名称更改为calculateRetail,则应该有效。