I am receiving an "undefined reference to" build error in my code that i do not know how to fix.
Here is my main code in C++ (the line of code that is in question is in bold):
#include <iostream>
#include<iomanip>
#include<stdio.h>
#include<stdlib.h>
using namespace std;
//Prototypes of functions
void sortTestScores(int*testScores,int size);
double averageTestScore(int*testScores,int size);
void printTestScores(int*testScores, int size);
int main()
{
//variable declaration
int *testScores;
int size;
int score;
double average;
//Prompt to enter size of array
cout<<"Enter size of array: ";
cin>> size;
testScores=new int[size];
//prompt to enter scores into array
cout<<"\nEnter "<<size
<<" positive values for the test scores"
<<endl;
for(int i=0;i<size;i++)
{
//prompt to enter a test score
cout<<"Score "<<(i+1)<<": ";
cin>>score;
//If negative score is entered
while(score<0)
{
cout<<"Again: " <<(i+1)<<": ";
cin>>score;
}
//stores score into array
testScores[i]=score;
}
//Print test scores before sorted
cout<<"\nTest scores before sorting: ";
printTestScores(testScores, size);
sortTestScores(testScores, size);
cout<<"Test scores after sorting: ";
printTestScores(testScores,size);
//Average test scores
average=averageTestScore(testScores, size);
//print average test scores
cout<<"Average test score: "<<setprecision(2)
<<fixed<<average<<endl;
//pause system
cout<<endl;
system("pause");
return 0;
}
----Here is my build log:
-------------- Clean: Debug in Module 9 (compiler: GNU GCC Compiler)---------------
Cleaned "Module 9 - Debug"
-------------- Build: Debug in Module 9 (compiler: GNU GCC Compiler)---------------
mingw32-g++.exe -Wall -fexceptions -g -c
"C:\Users\Bewm\Desktop\Computer Science 139\Module 9\main.cpp" -o
obj\Debug\main.o
mingw32-g++.exe -o "bin\Debug\Module 9.exe" obj\Debug\main.o
obj\Debug\main.o: In function `main':
C:/Users/Bewm/Desktop/Computer Science 139/Module 9/main.cpp:54:
undefined reference to `averageTestScore(int*, int)'
collect2.exe: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 0 second(s))
2 error(s), 0 warning(s) (0 minute(s), 0 second(s))
#include <iostream>
#include<iomanip>
#include<stdio.h>
#include<stdlib.h>
using namespace std;
//Prototypes of functions
void sortTestScores(int*testScores,int size);
double averageTestScore(int*testScores,int size);
void printTestScores(int*testScores, int size);
int main()
{
//variable declaration
int *testScores;
int size;
int score;
double average;
//Prompt to enter size of array
cout<<"Enter size of array: ";
cin>> size;
testScores=new int[size];
//prompt to enter scores into array
cout<<"\nEnter "<<size
<<" positive values for the test scores"
<<endl;
for(int i=0;i<size;i++)
{
//prompt to enter a test score
cout<<"Score "<<(i+1)<<": ";
cin>>score;
//If negative score is entered
while(score<0)
{
cout<<"Again: " <<(i+1)<<": ";
cin>>score;
}
//stores score into array
testScores[i]=score;
}
//Print test scores before sorted
cout<<"\nTest scores before sorting: ";
printTestScores(testScores, size);
sortTestScores(testScores, size);
cout<<"Test scores after sorting: ";
printTestScores(testScores,size);
//Average test scores
average=averageTestScore(testScores, size);
//print average test scores
cout<<"Average test score: "<<setprecision(2)
<<fixed<<average<<endl;
//pause system
cout<<endl;
system("pause");
return 0;
}
void sortTestScores(int *values,int numValues){
int i, j;
int temp;
// outer loop to travel through the
all elements
for (i = 0; i < numValues - 1;
i++) {
// inner loop to
compare the outer loop elements
for (j = 0; j
< numValues - i - 1; j++)
// if element at j< than j+1 than swap
both
if (values[j] > values[j + 1]) {
// swap logic
temp = values[j];
values[j] =
values[j+1];
values[j+1] = temp;
}
}
}
double averageTestScore(int*testScores,int size){
double sum=0;
for(int i=0;i<size;i++)
sum+=testScores[i];
double avg=sum/size;
return avg;
}
void printTestScores(int*testScores,int size){
for(int i=0;i<size;i++)
cout<<testScores[i]<<" ";
cout<<endl;
}

Note : Please comment below if you have concerns. I am here to help you
If you like my answer please rate and help me it is very Imp for me
I am receiving an "undefined reference to" build error in my code that i do not...
Am I getting this error because i declared 'n' as an int, and then asking it to make it a double? This is the coude: #include "stdafx.h" #include <iostream> #include <fstream> #include <string> #include <algorithm> #include <vector> using namespace std; void sort(double grades[], int size); char calGrade(double); int main() { int n; double avg, sum = 0;; string in_file, out_file; cout << "Please enter the name of the input file: "; cin >> in_file; ...
I have 2 issues with the C++ code below. The biggest concern is that the wrong file name input does not give out the "file cannot be opened!!" message that it is coded to do. What am I missing for this to happen correctly? The second is that the range outputs are right except the last one is bigger than the rest so it will not output 175-200, it outputs 175-199. What can be done about it? #include <iostream> #include...
C++ getline errors I am getting getline is undefined error messages. I would like the variables to remain as strings. Below is my code. #include <iostream> #include<string.h> using namespace std; int index = 0; // variable to hold how many customers are entered struct Address //Structure for the address. { int street; int city; int state; int zipcode; }; // Customer structure struct Customer { string firstNm, lastNm; Address busAddr, homeAddr; }; // Functions int displayMenu(); Customer getCustomer(); void showCustomer(Customer);...
Am I using the right cin statement to take in values for my array? If I print them out it prints "0x61fea0" with the input 1 2 3 4 5 ///////////////////////////////// #include <iostream> using namespace std; const int ARRAY_LENGTH = 5; int main(){ int numbers[ARRAY_LENGTH]; int threshold; //@todo prompt user to enter array values cout << "Please input 5 numbers: " << endl; for(int i = 0; i < ARRAY_LENGTH; i++){ //@todo add cin statement to read in values for...
--C++-- --spc16-7.cpp-- // Chapter 16, Programming Challenge 7: TestScores class #include <iostream> #include "TestScores.h" #include "NegativeScore.h" using namespace std; int main() { // Constant for the number of test scores const int NUM_SCORES = 5; try { // Create an array of valid scores. int myScores[NUM_SCORES] = { 88, 90, 93, 87, 99 }; // Create a TestScores object. //TestScores myTestScores(myScores, NUM_SCORES); // optional constructor TestScores myTestScores(myScores);...
read in numbers into array , print out, sort - my program reads in and prints out but crashes before the sort - crashes after it prints out the scores - *important I have to use pointers!!!! c++ #include <iostream> using namespace std; void sortarray(int *tarray, int ); void displayarray(int *[], int); void averageshowarray(int *[], int); int main() { int Size; int count; cout << "enter the size: " << endl; cin >> Size; int...
What did I do wrong with this C++ code? Assume that we don't need to ask users for the number of students. #include <iostream> #include <iomanip> using namespace std; int main() { float *grades; // a pointer used to point to an array int size; int count = 0; // track the number of grade/student float grade; // the grade of a student float average, total; // average grade and total grades //**************start your code here************************ cout<<"How many student grades...
I want to change this code and need help. I want the code to not use parallel arrays, but instead use one array of struct containing the data elements, String for first name, String for last name,Array of integers for five (5) test scores, Character for grade. If you have any idea help would be great. #include #include #include #include using namespace std; const int NUMBER_OF_ROWS = 10; //number of students const int NUMBER_OF_COLUMNS = 5; //number of scores void...
I need to update this C++ code according to these instructions.
The team name should be "Scooterbacks".
I appreciate any help!
Here is my code:
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
void menu();
int loadFile(string file,string names[],int jNo[],string
pos[],int scores[]);
string lowestScorer(string names[],int scores[],int size);
string highestScorer(string names[],int scores[],int size);
void searchByName(string names[],int jNo[],string pos[],int
scores[],int size);
int totalPoints(int scores[],int size);
void sortByName(string names[],int jNo[],string pos[],int
scores[],int size);
void displayToScreen(string names[],int jNo[],string pos[],int
scores[],int size);
void writeToFile(string...
I am getting an error that the variable num was not declared in the scope on the line of code that has; while(num != 5). Do you know how to fixe this error? #include <iostream> #include <iomanip> #include <string> #include<fstream> #include <cstring> using namespace std; //Declare the structure struct Games { string visit_team; int home_score; int visit_score; }; // Function prototypes int readData(Games *&stats); int menu(); void pickGame(Games *&stats, int size); void inputValid (Games *&stats, int size); void homeTotal(Games *&stats,...