我有了讀取兩個輸入文件,並從兩個文件中的某些數據進行排序的程序。我想通大部分的事情了,但我一直試圖將嚴格陣列傳遞到我的功能,但它不能正常工作。我的程序中顯示許多錯誤,「錯誤:調用沒有匹配的函數‘getPercentScore’」
int main()
{
int labNumber=8;
string labName = "MATH ANYONE";
printHeader(labName, labNumber);
ifstream infile; //INPUT input file stream
struct test {
string firstName; //INPUT student first name
string lastName; //INPUT student last name
string tempfirstName; //INPUT temporary first name used to place into actual
string templastName; //INPUT temporary last name used to place into actual
string tempId; //INPUT temporary id used to compare with actual
string studentId; //INPUT student id
double courseScore; //OUTPUT student score %
char courseGrade; //OUTPUT student letter grade
string answers; //INPUT student answer
};
test *table[30];
這只是我的代碼的一部分;我所說的一個輸入文件functions.cpp
for (int i=0;i<studentCount;i++)
{
double percent=0;
getPercentScore(table[30], key);
}
functions.cpp:
double getPercentScore(test *, string key)
{
double tempscore=0;
double percent;
for (int i=0;i<20;i++)
{
if (table[i].answers[i] == key[i])
{
tempscore = tempscore + 2; //add two if answer is correct
}
else if (table[i].answers[i] == '_')
{
tempscore = tempscore + 0;//add zero if answer if unanswered
}
else
{
tempscore = tempscore - 1;//subtract one for wrong answer
}
}
percent = tempscore/40;
percent = percent*100;
return percent;
}
我的計劃已經給我這個錯誤,我不知道如何解決這個問題:
。 ./lab8.cpp:112:3:錯誤:調用 'getPercentScore' getPercentScore沒有匹配的函數(表[30],密鑰); ^ ~~~~~~~~~~~~~~ ../lab8.cpp:33:8:注:候選人功能並不可行:沒有已知的由「測試*」轉換爲「測試*」爲1參數 雙getPercentScore(試驗*,串鍵);
任何幫助將大大apreciated。
注意,如果你聲明'測試*表[ 30];',使用'table [30]'以後會引起麻煩。 – fzd
如果傳遞'測試[30]',要傳遞的陣列的方法的一個孤獨位置。我認爲你的意思是'getPercentScore(test [i],key);'在你的循環中? – Shirkam
你忘了發佈所有#include指令。他們很重要,在發佈您的問題之前絕對不要編輯它們。 –