error LNK2019: unresolved external symbol "double __cdecl setTotalCost(void)"

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Rafael Douglas
    New Member
    • Feb 2011
    • 1

    error LNK2019: unresolved external symbol "double __cdecl setTotalCost(void)"

    Hello All, I was writing a program and ran across this error:

    error LNK2019: unresolved external symbol "double __cdecl setTotalCost(vo id)" (?setTotalCost@ @YANXZ) referenced in function _main
    1>c:\users\rafa el jr\documents\vi sual studio 2010\Projects\I nventory CS226\Debug\Inv entory CS226.exe : fatal error LNK1120: 1 unresolved externals

    Can anyone please tell me where my error is or what i'm doing wrong?


    here is my code:

    Code:
    #include <iostream>
    #include <string>
    #include "Inventory.h"
    #include <limits>
    /*using std::cin;
    using std::cout;
    using std::endl;	*/
    using namespace std;
    
    int main()
    {
    	int itemNumber, quantity;
    	double cost;
    	bool failed;
    	Inventory uItem;
    	double setTotalCost(); //function prototype
    	do
    		{
    		// User entering Item Number
    		uItem.setItemNumber(1);
    		cout<< "Please enter the Item number: "<< endl;
    		cin>> itemNumber;
    		if(itemNumber < 0 || itemNumber > 100 )
    		{
    			cout << "Sorry we do not accept negative values for Item Number" << endl;
    			failed=true;
    		}
    		else
    		{
    			failed=false;
    			cout << "Item Number entered: "<< itemNumber<< endl;
    		}while (failed == true ||  itemNumber < 0 );  // If user enters 0, then exit out
    
    
    		// User entering Quantity Amount
    		uItem.setQuantity(1);
    		cout<< "Please enter the Quantity Amount: "<< endl;
    		cin>> quantity;
    		if(quantity < 0 || quantity > 100 )
    		{
    			cout << "Sorry we do not accept negative values for the Quantity Amount" << endl;
    			failed=true;
    		}
    		else
    		{
    			failed=false;
    			cout << "Quantity Amount entered: "<< quantity<< endl;
    		}while (failed == true ||  quantity < 0 );  // If user enters 0, then exit out
    
    
    		// User entering Cost
    		uItem.setCost(1);
    		cout<< "Please enter the Cost of the Item: "<< endl;
    		cin>> cost;
    		if(cost < 0 || cost > 100 )
    		{
    			cout << "Sorry we do not accept negative values for the Item Cost" << endl;
    			failed=true;
    		}
    		else
    		{
    			failed=false;
    			cout << "Item Cost entered: "<< cost<< endl;
    		}
    		}while (failed == true ||  cost < 0 );  // If user enters 0, then exit out
    
    
    		// Calculation of Total Cost
    		cout<< " What is the Total Cost? "<<endl;
    		cout<< " The Total Cost is: "<< "$" <<setTotalCost<<endl;
    
    		system("pause");
    		return 0;
    	}
    Last edited by Niheel; Feb 15 '11, 08:16 AM.
  • horace1
    Recognized Expert Top Contributor
    • Nov 2006
    • 1510

    #2
    the linker is unable to find the function prototyped in the statement
    Code:
    double setTotalCost(); //function prototype
    have you spelt the name correctly? is it in another .cpp file?
    also when you call it
    Code:
    cout<< " The Total Cost is: "<< "$" <<setTotalCost<<endl;
    you have missed the ()

    Comment

    • Oralloy
      Recognized Expert Contributor
      • Jun 2010
      • 988

      #3
      Actually, the use of setTotalCost in the output line will likely just print the hex value of the address of the function. That's a logic error, not a coding error.

      The other thing to check is that you didn't spell the word differently in two places - setTotalCost and SetTotalCost are two different function names.

      Lastly, make sure you aren't compiling setTotalCost as a "C" function or placing it in a different namespace from your main(...)

      Good luck with your assignment.

      Oralloy

      Comment

      Working...