Tuesday 15 April 2014

ld returned 1 error exit status C++ -



ld returned 1 error exit status C++ -

i maintain getting "undefined reference 'x'" x function prototypes. have functions mapped out main still needs work fyi. want prepare ld homecoming error 1 before pressing on can't seem pin point issue.

#include <iostream> #include <iomanip> #include <cmath> using namespace std; //symbolic constants const int max=11; //function prototypes int buildquizarray(int); void printarray(string,int,int); double calcquizaverage(int,int); void sortarray(int,int); int main () { int quizscores[max]; int compquiz; int temparray[max]; int average; compquiz = buildquizarray(quizscores[max]); quizscores[max]=temparray[max]; average = calcquizaverage(quizscores[max], compquiz); cout<<endl<<"your quiz average "<<average<<endl; printarray ("quiz scores", temparray[max], compquiz); sortarray(temparray[max], compquiz); } int buildquizarray(int quizarray[]) { int numquiz, input, a; a=0; numquiz=1; cout << "enter score quiz "<<numquiz<<" (-1 quit): "; cin >> input; while (input != -1) { quizarray[a] = input; a++; numquiz++; cout<< "enter score quiz "<<numquiz<<" (-1 quit): "; cin >> input; } homecoming a+1; } void printarray(string reporttitle, int quizarray[], int numberofquizzes) { int a; cout<< reporttitle <<endl<<"-----------"<<endl; (a=0; a<numberofquizzes; a++) { cout<< "quiz " << <<": " << setw(2) <<quizarray[a] <<"/10"<<endl; } } double calcquizaverage(int quizarray[], int numberofquizzes) { int sum, lowsum, avg, a; = 0; sum = 0; lowsum = quizarray[0] + quizarray[1]; (a=0; a< numberofquizzes; a++) { sum += quizarray[a]; } if (numberofquizzes <= 2) { avg = sum / (10 * numberofquizzes) * 100; } else { (sum - lowsum) / (10 * (numberofquizzes - 2)) * 100; } homecoming avg; } void sortarray(int quizarray[], int numberofquizzes) { int min, a, b, temp; (a=0; a<numberofquizzes; a++) { min = a; } for(b=a+1; b<numberofquizzes; a++) { if (quizarray[a] < quizarray[min]) { min = b; } } temp = quizarray[a]; quizarray[a]=quizarray[min]; quizarray[min]=temp; }

you declare:

int buildquizarray(int);

but define:

int buildquizarray(int quizarray[]) ...

int[] not same int.

also: passing int functions when phone call them, though; note e.g. quizscores[max] maxth element of quizscores , int, beyond end of array, , isn't want doing.

if had guess how got here i'd guess had right, had unknowingly declared prototypes incorrectly (int instead of int[]), tacked [max] on arrays passing functions compile, ran inevitable linker problem led here. if that's did, wasn't quite right approach.

what mean is:

for functions take arrays, declare them properly:

int buildquizarray (int[]);

pass array pointer function when calling it:

buildquizarray(quizscores);

leave declarations as-is, fine (syntax-wise).

c++ exit ld

No comments:

Post a Comment