Error with strings and referencing, please help.

I'm working on a homework assignment and I got rid of all the errors and now I'm getting some jibberish that is related to strings and references. I have no idea what I'm doing.

One line of the error for example is :

assignment3.cpp:(.text+0x51): undefined reference to `check_int(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)'

It repeats that for every string that I've used. Thank you for your help!
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
  
#include <iostream>
#include <string>
#include <cstdlib>

using namespace std;

string check_int(string);
int convrt_num(string);

int prompt_test(string &test){
        int test1;
        cout << "How many tests?";
        cin >> test;


        test = check_int(test);
        test1 = convrt_num(test);

        return test1;
}

int prompt_quizzes(string &quiz){
        int quiz1;
        cout << "How many quizzes?";
        cin >> quiz;

        quiz = check_int(quiz);
        quiz1 = convrt_num(quiz);

        return quiz1;
}

int prompt_assign (string &assign){

        int assign1;
        cout << "How many assignments?";
        cin >> assign;

        assign = check_int(assign);
        assign1 = convrt_num (assign);

        return assign1;

}

int prompt_lab (string &lab){

        int lab1;
        cout << "How many labs?";
        cin >> lab1;
    
             lab = check_int(lab);
        lab1 = convrt_num (lab);

        return lab1;
}

int prompt_final (int finals){

        int x=0;
        cout << "Is there a final? Enter 1 for yes, enter 0 for no:";
        cin >> finals;

        while (x == 0) {
                if(finals !=1 || finals !=0) {
                        cout << "You didn't enter a 1 or 0, please try again";
                        cin >> finals;
                        x = 0;
                }
                        else
                        x = 1;
                }
        return finals;
}

string check_int(string &num){
        for (int i = 0; i < num.length(); i++){
                if(!(num.at(i) > 0 && num.at(i) < 9)){
                        cout << "This isn't a number, try again ya dingus." << endl;
                        cin >> num;
                        i = -1;
                }
        }
        return num;
}

int convrt(string num){
        int num1 = atoi(num.c_str());
        return num1;
}

int main(){
        string test;int test1;
        test1 = prompt_test(test);
        cout << "There are: " << test1 << " tests. " << endl;
return 0;
}


Your function prototype for check_int() doesn't match the function implementation.
The following are not the same.
1
2
3
string check_int(string);
...
string check_int(string &num){
I changed it but the error is still there?
Post your modified code, along with the complete error messages, all of them, exactly as they appear in your development environment.
[code]
#include <iostream>
#include <string>
#include <cstdlib>

using namespace std;

string check_int(string &x);
int convrt_num(string &x);

int prompt_test(string &test){
int test1;
cout << "How many tests?";
cin >> test;


test = check_int(test);
test1 = convrt_num(test);

return test1;
}

int prompt_quizzes(string &quiz){
int quiz1;
cout << "How many quizzes?";
cin >> quiz;

quiz = check_int(quiz);
quiz1 = convrt_num(quiz);

return quiz1;
}

int prompt_assign (string &assign){

int assign1;
cout << "How many assignments?";
cin >> assign;

assign = check_int(assign);
assign1 = convrt_num (assign);

return assign1;

}

int prompt_lab (string &lab){

int lab1;
cout << "How many labs?";
cin >> lab1;

lab = check_int(lab);
lab1 = convrt_num (lab);

return lab1;
}

int prompt_final (int finals){

int x=0;
cout << "Is there a final? Enter 1 for yes, enter 0 for no:";
cin >> finals;

while (x == 0) {
if(finals !=1 || finals !=0) {
cout << "You didn't enter a 1 or 0, please try again";
cin >> finals;
x = 0;
}
else
x = 1;
}
return finals;
}

string check_int(string &num){
for (int i = 0; i < num.length(); i++){
if(!(num.at(i) > 0 && num.at(i) < 9)){
cout << "This isn't a number, try again ya dingus." << endl;
cin >> num;
i = -1;
}
}
return num;
}

int convrt_num(string &num){
int num1 = atoi(num.c_str());
return num1;
}

int main(){
string test;int test1;
test1 = prompt_test(test);
cout << "There are: " << test1 << " tests. " << endl;
return 0;
}
[\code]


The full error is :
/tmp/ccM4pNm1.o: In function `prompt_test(std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)':
assignment3.cpp:(.text+0x17c): undefined reference to `convrt_num(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
/tmp/ccM4pNm1.o: In function `prompt_quizzes(std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)':
assignment3.cpp:(.text+0x257): undefined reference to `convrt_num(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
/tmp/ccM4pNm1.o: In function `prompt_assign(std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)':
assignment3.cpp:(.text+0x332): undefined reference to `convrt_num(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
/tmp/ccM4pNm1.o: In function `prompt_lab(std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)':
assignment3.cpp:(.text+0x40d): undefined reference to `convrt_num(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
collect2: ld returned 1 exit status
I don't get any compile errors when I compile your code and the prototype seems to match the implementation.
Topic archived. No new replies allowed.