Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I am writing a C++ program on Xcode and keep getting a build error. Can someone

ID: 2246436 • Letter: I

Question

I am writing a C++ program on Xcode and keep getting a build error. Can someone with Xcode please find out what libraries to include, I believe that may be my issue as the prgram runs fine on my terminal.

Code below:

#include <stdio.h>

#include <iostream>

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;

}

Explanation / Answer

This build error could be because you need to select the exact stdc++ . Its working fine in my Xcode

====================================================================
Idea 1:

Try the below steps and let me know if it works:


Click on your project ,

Then click Targets -> Then Click build settings Scroll down until you see "LLVM GCC 4.2 - Languages"
(Nowadays for newXcode it will say "Apple LLVM compiler 4.2").Locate the "C++ Standard Library" key, and change its value from libc++ to ( libstdc++ or default compiler )

=====================================================================================================

Idea 2:

The build error could be :


You need to Right click the file inside XCOde and select GETinfo. Make sure File Type is

anything.cpp.cpp

====================================================================

Idea 3

Steps :

1. Click on "Show the Project Navigator" icon, a small folder in the top left.

2. Click on the top most item, which is your project. In the window that is displayed, select your primary target.

3. In the build settings tab, select All settings, and select "Combined" instead of "Levels".

Scroll down until you see the "Apple LLVM compiler 4.1 - Language" group.

Find the "C++ Standard Library" key, and change its value from libc++ to ( libstdc++ or default compiler )

Thanks, let me know if your issue is resolved , If not let me know the error in Comments section. I will surely respond

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote