Question: I am doing a C++ program in Xcode and keep getting the following build failure (even though it runs fine on my terminal): Showing Recent
I am doing a C++ program in Xcode and keep getting the following build failure (even though it runs fine on my terminal):
Showing Recent Issues
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I believe the issue may be with iostream or cstdio libraries.
Code below:
#include
#include
using namespace std;
double findAverageScore(int scores[], int numJudges){
//3 double
double highest = 0;
double lowest = scores[0]; //NOTE: lowest set to 1st index
double total = 0;
for(int i = 0; i < numJudges; i++){
total += scores[i];
if(scores[i] >= highest){
highest = scores[i];
}
if(scores[i] <= lowest){
lowest = scores[i];
}
}
total = total - highest - lowest;
return total/(numJudges - 2);
}
int main(){
//4 int and 1 double
int N; //number of judges
int contestant;
int highestContestant = 0;
int highScore = 0;
double averageScore;
printf("Enter the number of judges: ");
cin >> N;
int scores[N];
printf("Number of judges entered: %d", N);
while(true){
printf("Enter the contestant number: ");
cin >> contestant;
if(contestant > 0){
puts("Enter scores: ");
for(int i = 0; i < N; i++){
cin >> scores[i];
}
averageScore = findAverageScore(scores, N);
if(averageScore >= highScore){
highestContestant = contestant;
highScore = averageScore;
}
}else{
printf("Contestant %d had the highest score ", highestContestant);
break;
}
}
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
