Linker problems?

Everytime I try to compile I get this error:

Undefined symbols for architecture x86_64:
"Measure(char)", referenced from:
_main in program5-7d9fc2.o
"Verify2(char)", referenced from:
Measure() in program5-7d9fc2.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I honestly have no clue how to fix this. If anyone could help I would really appreciate it! thanks!

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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
  //------------------------------------------------------------------------------
//Programmer: Jennifer Preuss                Student ID: 18159635
//Program: #5                                Filename: program5.cpp
//Due: 4/2/18                                Class: CS1971
//------------------------------------------------------------------------------
//Program Description
//This program takes input from the user in the form of height or length in feet
//converts it to inches, and then calculates the maximum allowable deflection.
//


#include <iostream>

using namespace std;

void Welcome();

char Measure(char beamtype);

void UserInput(float& Length_Height);

bool Verify(float Length_Height);

bool Verify2(char beamtype);

float Conversion(float Length_Height);

void Dmax1(float Length_Height, char beamtype);
void Dmax2(float Length_Height, char beamtype);
void Dmax3(float Length_Height, char beamtype);
void Dmax4(float Length_Height, char beamtype);

char RunAgain();


int main()
{
   char beamtype;
   char useranswer;
   float Length_Height;

   do
   {

      Welcome();

      UserInput(Length_Height);

      Measure(beamtype);

      Conversion(Length_Height);

      Dmax1(Length_Height, beamtype);
      Dmax2(Length_Height, beamtype);
      Dmax3(Length_Height, beamtype);
      Dmax4(Length_Height, beamtype);

      useranswer = RunAgain();

   }while(useranswer == 'Y' || useranswer == 'y');

   return 0;

}

void Welcome()
{
   cout << "Welcome to the max deflection calculator!" << endl;

}

void UserInput(float& Length_Height)
{
   bool Verification;
   do
   {

      cout << "Please enter your value of beam length or height." << endl;
      cin  >> Length_Height;

      Verification = Verify(Length_Height);

      if(!Verification)
      {
         cout << "Invalid input." << endl;
         cout << "Please enter a number greater than 10.";
      }

   }while(!Verification);

}

char Measure()
{
  char beamtype;
  bool Verification2;
  do
  {

     cout << "Please indicate the type of structual element." << endl;
     cout << " 'I' for interior, 'E' for exterior, 'R' for roof, 'A' for other: ";
     cin >> beamtype;

     cout << "here is beamtype: " << beamtype << endl;

     Verification2 = Verify2(beamtype);

     if(!Verification2)
     {

        cout << "Invalid input." << endl;
        cout << "Please enter either 'I', 'E', 'R', or 'A' ";
     }

  }while(!Verification2);
  return(beamtype);

}

bool Verify(char beamtype)
{

   if((beamtype == 'I' || beamtype == 'i' || beamtype == 'E' || beamtype == 'e' || beamtype == 'R' || beamtype == 'r' || beamtype == 'A' || beamtype == 'a'))
   {
      return true;
   }
   else
   {
      return false;
   }
}

bool Verify(float Length_Height)
{

   if(Length_Height <= 10)
   {
      return false;
   }
   else
   {
      return true;
   }
}
float Conversion(float Length_Height)
{

   const int ruler = 12;
   Length_Height = Length_Height * ruler;
   return(Length_Height);

}

void Dmax1(float Length_Height, char beamtype)
{
   float dmaxoutput;
   const int num1 = 180;

   if (beamtype == 'I' || beamtype == 'i')
   {
     dmaxoutput = Length_Height / num1;
     cout << "The maximum allowable deflection is: " << dmaxoutput << endl;
   }
}

void Dmax2(float Length_Height, char beamtype)
{
   float dmaxoutput;
   const int num1 = 360;

   if (beamtype == 'E' || beamtype == 'e')
   {
     dmaxoutput = Length_Height / num1;
     cout << "The maximum allowable deflection is: " << dmaxoutput << endl;
   }

}

void Dmax3(float Length_Height, char beamtype)
{
   float dmaxoutput;
   const int num1 = 180;

   if (beamtype == 'R' || beamtype == 'r')
   {
     dmaxoutput = Length_Height / num1;
     cout << "The maximum allowable deflection is: " << dmaxoutput << endl;
   }

}

void Dmax4(float Length_Height, char beamtype)
{
   float dmaxoutput;
   const int num1 = 240;

   if (beamtype == 'A' || beamtype == 'a')
   {
     dmaxoutput = Length_Height / num1;
     cout << "The maximum allowable deflection is: " << dmaxoutput << endl;
   }

}

char RunAgain()
{
   char useranswer;
   cout << "Would you like to use the program again? 'Y' or 'N' ?";
   cin  >> useranswer;

   return(useranswer);
}
closed account (E0p9LyTq)
Your function declaration: char Measure(char beamtype);

Your function definition: char Measure() { }

What's missing? The parameter you said your function would take. The function signature doesn't match.

By the look of your function code you probably should remove the parameter from your function declaration.

bool Verify2(char beamtype); should be bool Verify(char beamtype); Since you are overloading the function.
Last edited on
Okay so that worked, and it compiles, and runs, but when I run it, it won't run any of the Dmax functions, but will ask if the user wants to run again. any thoughts?
Last edited on
closed account (E0p9LyTq)
Line 49 in main should be:

beamtype = Measure();

you are returning a char that represents "beamtype."
To correspond to the definition on line 93 your declaration of function Measure() on line 18 should be
char Measure();
and you should call it in main() on line 49 with
beamtype = Measure();


You haven't defined a function Verify2. Line 120 should probably be
bool Verify2(char beamtype)


You really should refactor your code so as not to have to call 4 separate Dmax functions, which individually only do anything for one beam section.
unfortunately @lastchance, my professor wants four separate functions. almost everything done by this program must be done with functions. thanks for helping with the linker problem, it compiles, and runs, but when I run it, it won't run any of the Dmax functions but will ask if the user wants to run again. any thoughts?
Can you post (below this) your now-compileable code. Can't see what you have changed otherwise.
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
//------------------------------------------------------------------------------
//Programmer: Jennifer Preuss                Student ID: 18159635
//Program: #5                                Filename: program5.cpp
//Due: 4/2/18                                Class: CS1971
//------------------------------------------------------------------------------
//Program Description
//This program takes input from the user in the form of height or length in feet
//converts it to inches, and then calculates the maximum allowable deflection.
//


#include <iostream>

using namespace std;

void Welcome();

char Measure();

void UserInput(float& Length_Height);

bool Verify(float Length_Height);

bool Verify2(char beamtype);

float Conversion(float Length_Height);

void Dmax1(float Length_Height, char beamtype);
void Dmax2(float Length_Height, char beamtype);
void Dmax3(float Length_Height, char beamtype);
void Dmax4(float Length_Height, char beamtype);

char RunAgain();


int main()
{
   char beamtype;
   char useranswer;
   float Length_Height;

   do
   {

      Welcome();

      UserInput(Length_Height);

      Measure();

      Conversion(Length_Height);

      Dmax1(Length_Height, beamtype);
      Dmax2(Length_Height, beamtype);
      Dmax3(Length_Height, beamtype);
      Dmax4(Length_Height, beamtype);

      useranswer = RunAgain();

   }while(useranswer == 'Y' || useranswer == 'y');

   return 0;

}

void Welcome()
{
   cout << "Welcome to the max deflection calculator!" << endl;

}

void UserInput(float& Length_Height)
{
   bool Verification;
   do
   {

      cout << "Please enter your value of beam length or height." << endl;
      cin  >> Length_Height;

      Verification = Verify(Length_Height);

      if(!Verification)
      {
         cout << "Invalid input." << endl;
         cout << "Please enter a number greater than 10.";
      }

   }while(!Verification);

}

char Measure()
{
  char beamtype;
  bool Verification2;
  do
  {

     cout << "Please indicate the type of structual element." << endl;
     cout << "'I' for interior, 'E' for exterior, 'R' for roof, 'A' for other: ";
     cin >> beamtype;

     cout << "here is beamtype: " << beamtype << endl;

     Verification2 = Verify2(beamtype);

     if(!Verification2)
     {

        cout << "Invalid input." << endl;
        cout << "Please enter either 'I', 'E', 'R', or 'A' ";
     }

  }while(!Verification2);
  return(beamtype);

}

bool Verify2(char beamtype)
{

   if((beamtype == 'I' || beamtype == 'i' || beamtype == 'E' || beamtype == 'e' || beamtype == 'R' || beamtype == 'r' || beamtype == 'A' || beamtype == 'a'))
   {
      return true;
   }
   else
   {
      return false;
   }
}

bool Verify(float Length_Height)
{

   if(Length_Height <= 10)
   {
      return false;
   }
   else
   {
      return true;
   }
}
float Conversion(float Length_Height)
{

   const int ruler = 12;
   Length_Height = Length_Height * ruler;
   return(Length_Height);

}

void Dmax1(float Length_Height, char beamtype)
{
   float dmaxoutput;
   const int num1 = 180;

   if (beamtype == 'I' || beamtype == 'i')
   {
     dmaxoutput = Length_Height / num1;
     cout << "The maximum allowable deflection is: " << dmaxoutput << endl;
   }
}

void Dmax2(float Length_Height, char beamtype)
{
   float dmaxoutput;
   const int num1 = 360;

   if (beamtype == 'E' || beamtype == 'e')
   {
     dmaxoutput = Length_Height / num1;
     cout << "The maximum allowable deflection is: " << dmaxoutput << endl;
   }

}

void Dmax3(float Length_Height, char beamtype)
{
   float dmaxoutput;
   const int num1 = 180;

   if (beamtype == 'R' || beamtype == 'r')
   {
     dmaxoutput = Length_Height / num1;
     cout << "The maximum allowable deflection is: " << dmaxoutput << endl;
   }

}

void Dmax4(float Length_Height, char beamtype)
{
   float dmaxoutput;
   const int num1 = 240;

   if (beamtype == 'A' || beamtype == 'a')
   {
     dmaxoutput = Length_Height / num1;
     cout << "The maximum allowable deflection is: " << dmaxoutput << endl;
   }

}

char RunAgain()
{
   char useranswer;
   cout << "Would you like to use the program again? 'Y' or 'N' ?";
   cin  >> useranswer;

   return(useranswer);
}
Last edited on
closed account (E0p9LyTq)
@jen400,

You have four separate functions that do exactly the same thing, except for checking what the passed character is.
@furryguy

I have to have four separate functions. From my prompt given by my instructor:


a. A function to receive length (L) or height (H) of the beam from the user.
b. A function to receive the structural element type character option input from the user.
c. Two separate validation functions for each of the two inputs. The input for L/H should be greater than 10 feet, and the character option input should be one of the four valid characters that you have used in your program. If either one (or both) of the inputs are invalid, your program should ask the user to re-enter a valid input.
d. A function to convert the L/H user input value in feet to inches.
e. Separate functions to compute the Dmax in all of the four cases.
Please put that in code tags @jen400

I can see that you ignored my suggestion of writing
beamtype = Measure();
and instead just wrote
Measure();

So the beamtype isn't read in ... and hence there isn't anything for any of the Dmax functions to do.


Also, if you write
Conversion(Length_Height);
in main() then NOTHING will change. You usually assign a non-void function to some variable. In this instance you probably want (the not-very-obvious)
Length_Height = Conversion(Length_Height);
Alternatively, you could change the declaration and definition of this function to pass Length_height as a reference, rather than via the return value.
Last edited on
my bad @last chance, thought I had, i updated it
OMG i understand now! it works! Thank you sooo much guys!!
closed account (E0p9LyTq)
it won't run any of the Dmax functions but will ask if the user wants to run again. any thoughts?

All four functions are being called, your function naming logic is messing things up.

Make the previous suggested changes, and it works as expected:
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#include <iostream>

using namespace std;

void Welcome();
char Measure();
void UserInput(float& Length_Height);
bool Verify(float Length_Height);
bool Verify(char beamtype);
float Conversion(float Length_Height);
void Dmax1(float Length_Height, char beamtype);
void Dmax2(float Length_Height, char beamtype);
void Dmax3(float Length_Height, char beamtype);
void Dmax4(float Length_Height, char beamtype);
char RunAgain();

int main()
{
   char beamtype;
   char useranswer;
   float Length_Height;

   do
   {
      Welcome();

      UserInput(Length_Height);

      beamtype = Measure();

      Conversion(Length_Height);

      Dmax1(Length_Height, beamtype);
      Dmax2(Length_Height, beamtype);
      Dmax3(Length_Height, beamtype);
      Dmax4(Length_Height, beamtype);

      useranswer = RunAgain();
   }
   while(useranswer == 'Y' || useranswer == 'y');

   return 0;
}

void Welcome()
{
   cout << "Welcome to the max deflection calculator!" << endl;
}

void UserInput(float& Length_Height)
{
   bool Verification;

   do
   {
      cout << "Please enter your value of beam length or height." << endl;
      cin  >> Length_Height;

      Verification = Verify(Length_Height);

      if (!Verification)
      {
         cout << "Invalid input." << endl;
         cout << "Please enter a number greater than 10.";
      }
   }
   while(!Verification);
}

char Measure()
{
   char beamtype;
   bool Verification2;
   do
   {
      cout << "Please indicate the type of structual element." << endl;
      cout << " 'I' for interior, 'E' for exterior, 'R' for roof, 'A' for other: ";
      cin >> beamtype;

      cout << "here is beamtype: " << beamtype << endl;

      Verification2 = Verify(beamtype);

      if(!Verification2)
      {
         cout << "Invalid input." << endl;
         cout << "Please enter either 'I', 'E', 'R', or 'A' ";
      }

   }
   while(!Verification2);
   return(beamtype);
}

bool Verify(char beamtype)
{
   if((beamtype == 'I' || beamtype == 'i' || beamtype == 'E' || beamtype == 'e' || beamtype == 'R' || beamtype == 'r' || beamtype == 'A' || beamtype == 'a'))
   {
      return true;
   }
   else
   {
      return false;
   }
}

bool Verify(float Length_Height)
{
   if(Length_Height <= 10)
   {
      return false;
   }
   else
   {
      return true;
   }
}
float Conversion(float Length_Height)
{
   const int ruler = 12;
   Length_Height = Length_Height * ruler;
   return(Length_Height);

}

void Dmax1(float Length_Height, char beamtype)
{
   float dmaxoutput;
   const int num1 = 180;

   if (beamtype == 'I' || beamtype == 'i')
   {
      dmaxoutput = Length_Height / num1;
      cout << "The maximum allowable deflection is: " << dmaxoutput << endl;
   }
}

void Dmax2(float Length_Height, char beamtype)
{
   float dmaxoutput;
   const int num1 = 360;

   if (beamtype == 'E' || beamtype == 'e')
   {
      dmaxoutput = Length_Height / num1;
      cout << "The maximum allowable deflection is: " << dmaxoutput << endl;
   }
}

void Dmax3(float Length_Height, char beamtype)
{
   float dmaxoutput;
   const int num1 = 180;

   if (beamtype == 'R' || beamtype == 'r')
   {
      dmaxoutput = Length_Height / num1;
      cout << "The maximum allowable deflection is: " << dmaxoutput << endl;
   }

}

void Dmax4(float Length_Height, char beamtype)
{
   float dmaxoutput;
   const int num1 = 240;

   if (beamtype == 'A' || beamtype == 'a')
   {
      dmaxoutput = Length_Height / num1;
      cout << "The maximum allowable deflection is: " << dmaxoutput << endl;
   }
}

char RunAgain()
{
   char useranswer;
   cout << "Would you like to use the program again? 'Y' or 'N' ?";
   cin  >> useranswer;

   return(useranswer);
}

Welcome to the max deflection calculator!
Please enter your value of beam length or height.
12
Please indicate the type of structual element.
 'I' for interior, 'E' for exterior, 'R' for roof, 'A' for other: i
here is beamtype: i
The maximum allowable deflection is: 0.0666667
Would you like to use the program again? 'Y' or 'N' ?n
Last edited on
Topic archived. No new replies allowed.