Need help with linking errors LNK2019 and LNK1120

Hello, everyone, I'm new here and I need some help with this project I am working on for school. Below is a partial segment of the project in question. The project has been worked on in Microsoft Visual C++ 2005 Express Edition.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include <iostream>
#include <string>
#include <sstream>
#include <math.h>
using namespace std;

int main()
{
    // local function prototypes (must be local!)
    bool doMore(void);
    //   TODO: code function prototype for calculator module
	double calculator();

    // local data declarations
    bool more;
    const int SIZE = 4;
    int index = 0;
	string statement;


    string doit[SIZE] = { "9.42 / 5",    // TODO: enter 2 statements
                          "11.267 + 3",
                          "13.13 - 4",
                          "19.19 * 2"
                           };
    double result;

    cout << " *** Start of Program *** " << endl;

    // Step #1: initialize test variable
    more = true;

    // Step #2: examine the variable
    while(more)
    {
        // Step #3: processing
        // TODO: complete the right side of the statement
        //  code the function call
        //STUDENT CODE BEGINS HERE
         result = calculator();
        //STUDENT CODE ENDS HERE

         cout << "The result of " << doit[index] << " is: " << result;

        // increment array counter
        index++;

        // reset array index
        if(index > (SIZE - 1))
            index = 0;

        // Step #4: alter or change test variable
        // does the user wish to do more? (function call)
        more = doMore();

    }   // end of outer loop

    // terminate program
    cout << " *** End of Program *** " << endl;

    cin.ignore();
    cin.get();

    return 0;
}

//--------------------------------------------------------------------//
// Function Name:   calculator()
// Purpose:         parse a string into operands & operator and
//                      compute the answer
//--------------------------------------------------------------------//
// Preconditions:    given a string parameter in the format of:
//                      operand1 operator operand2
//
// Postconditions:   the function has returned the double answer
// TODO: you are to use an istringstream object to parse the string
//    into individual identifiers
//    The istringstream object must be declared
//--------------------------------------------------------------------//
double calculator(string statement)
{  // code function to parse the string & compute the answer

   // declare function identifiers
    char operators;               // data ends up in these 4 identifiers
    float operand1;
    int operand2;
    double answer;
   // The identifier "operator" has been changed to "operators" so it would not be read 
   //	as an extra data type.

   // TODO: declare an istringstream object & initialize
   istringstream is;

   // TODO: parse the string stream into 3 identifiers
   is >> operand1;
   is >> operators;
   is >> operand2;
   

   // compute the average as a double (?casting anyone?)
   // allow for +, -, *, / operators
   switch(operators)
   {
      case '*':
         answer = operand1 * operand2;
         break;
      // TODO: complete the switch statement for other math operators
	  case '/':
		 answer = operand1 / operand2;
		 break;
	  case '+':
		 answer = operand1 + operand2;
		 break;
	  case '-':
		 answer = operand1 - operand2;
		 break;

   }

   // return the double answer
   return answer;
}


Now, the entire project is able to compile, but when I try to run it, these errors appear:

Linking...
U02_StringStreamLab2.obj : error LNK2019: unresolved external symbol "double __cdecl calculator(void)" (?calculator@@YANXZ) referenced in function _main
C:\Documents and Settings\HP_Administrator\My Documents\MATT\CIS 276\U02_StringStreamLab2\Debug\U02_StringStreamLab2.exe : fatal error LNK1120: 1 unresolved externals
Build log was saved at "file://c:\Documents and Settings\HP_Administrator\My Documents\MATT\CIS 276\U02_StringStreamLab2\Debug\BuildLog.htm"
U02_StringStreamLab2 - 2 error(s), 0 warning(s)

If anyone could help me with these problems, it would be greatly appriciated. Thanks in advance.
Last edited on

I am not sure this will resolve all your problems but you have your prototypes in your main.
1
2
3
4
5
6
7
8
int main()
{
   ...
    // local function prototypes (must be local!)
    bool doMore(void);
    //   TODO: code function prototype for calculator module
   double calculator();


The next thing your signature doesnt match the prototype for your calculator.

double calculator();
double calculator(string statement)
{
....
You call it as void

result = calculator();


Another thing doMore() has a signature but has not been implemented and you call it in your program.
more = doMore();
Last edited on
All right, thanks for the help, dolorx.
Topic archived. No new replies allowed.