2016-04-25 23 views
0

ユーザーが入力した等級の数。私はダイナミックな配列の割り当てに取り組んでいます。私は自分のコードに自信がありますが、Xcodeは私のソート機能にエラーを与えています。私はそれを正しくやっていると思っていましたが、明らかに何かが間違っています。私はまだ動的メモリ割り当てを把握しようとしています。だから私のエラーはどこから生成されているのでしょうか、私は原因がどこにあるのか分かりません。ここに私のフルプログラムがあります:Xcodeのエラー:オーバーロードされた関数への参照を参照できませんでした

// 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. 
} 

ありがとう!

+1

'スコア=新しいフロート(numOfScores);'私は真剣に疑いあなたはそれがないと思う何をしても、その。あなたが 'scores = new float [numOfScores];'を望んでいることを確かめてください。そして、 'float * score []'はあなたのパラメータの型には間違いありません。あなたは 'float score []'が必要です。 – WhozCraig

+0

[条件でdo-whileループ内で宣言された変数を使用する](http://stackoverflow.com/questions/18541304/use-variables-declared-inside-do-while-loop-in-the-condition) – LogicStuff

+0

そのエラーメッセージが修正されましたが、現在は「アルゴリズム」に関するエラーメッセージが表示されます。私も '#include 'を取り出してみましたが、まだエラーメッセージが出ます。何か案は? –

答えて

0

swapdo...whileループのローカルなので、while条件では使用できません。一つは、それに関連するエラーを期待するだろうが、あなたはusing namespace std;を持っているので、#include <algorithm>あなたは今、関数ポインタへstd::swapを変換しようとしているプログラム

while(swap); 

の範囲にstd::swap機能を導入しているが、それはASできませんそれは過負荷であり、使用するべき過負荷を知らない。 using namespace std;参照を使用しないようにする理由について、さらに読書のために

Why is “using namespace std” in C++ considered bad practice?

関連する問題