Anzahl der Noten, die ein Benutzer eingibt. Ich arbeite mit dynamischer Array-Zuweisung. Ich bin zuversichtlich in meinen Code, aber Xcode gibt mir einen Fehler in meiner Sortierfunktion. Ich dachte, dass ich es richtig gemacht habe, aber anscheinend stimmt etwas nicht, und ich bin mir nicht ganz sicher, wo. Ich versuche immer noch, die dynamische Speicherzuweisung herauszufinden, also bin ich mir sicher, dass das ist, wo mein Fehler generiert, ich weiß nur nicht, wo die Ursache ist. Hier ist mein komplettes Programm:Fehler in Xcode: Verweis auf überladene Funktion konnte nicht referenziert werden
// This program demonstrates the use of dynamic arrays
#include <iostream>
#include <algorithm>
#include <iomanip>
using namespace std;
//Function Prototypes
void sort(float *score[], int numOfScores);
int main()
{
float *scores;
int total = 0;
float average;
float numOfScores;
int count;
cout << fixed << showpoint << setprecision(2);
cout << "Enter the number of scores to be averaged and sorted.";
cin >> numOfScores;
scores = new float(numOfScores);
for (count = 0; count < numOfScores; count++)
{
cout << "Please enter a score:" << endl;
cin >> scores[count]; }
for (count = 0; count < numOfScores; count++)
{
total = total + scores[count];
}
average = total/numOfScores;
cout << "The average score is " << average << endl;
sort(*scores, numOfScores);
delete [] scores;
return 0;
}
//*******************************************
// Sort Function
// Bubble sort is used to sort the scores
//*******************************************
void sort(float *score[], int numOfScores)
{
do
{
bool swap = false;
for (int count = 0; count < (numOfScores -1); count++)
{
if (*score[count] > *score[count+1])
{
float *temp = score[count];
score[count] = score[count+1];
score[count+1] = temp;
swap = true;
}
}
}while(swap); //This is where I'm receiving the error.
}
Vielen Dank!
'Partituren = new Schwimmer (numOfScores);' Ich bezweifle ernsthaft, das tut, was Sie denken, es tut. Ziemlich sicher, du wolltest 'scores = new float [numOfScores];'. Und 'float * score []' ist sicherlich nicht korrekt für Ihren Parametertyp. Sie möchten 'float score []'. – WhozCraig
Mögliches Duplikat von [Benutze Variablen, die in der do-while-Schleife in der Bedingung deklariert sind] (http://stackoverflow.com/questions/18541304/use-variables-declared-inside-do-while-loop-in-the-condition) – LogicStuff
Das hat diese Fehlermeldung behoben, aber jetzt bekomme ich eine Fehlermeldung bezüglich "Algorithmus". Ich habe sogar versucht, '#include' herauszunehmen und ich bekomme immer noch eine Fehlermeldung. Irgendwelche Ideen? –