c++ - My program is showing many errors, "error: no matching function for call to 'getPercentScore'" -
i have program has read 2 input files , sort data 2 files. have figured of things out keep trying pass stricter array function not working.
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 place actual string templastname; //input temporary last name used place actual string tempid; //input temporary id used compare 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];
this part of code; have 1 input file called functions.cpp
(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; (int i=0;i<20;i++) { if (table[i].answers[i] == key[i]) { tempscore = tempscore + 2; //add 2 if answer correct } else if (table[i].answers[i] == '_') { tempscore = tempscore + 0;//add 0 if answer if unanswered } else { tempscore = tempscore - 1;//subtract 1 wrong answer } } percent = tempscore/40; percent = percent*100; return percent; }
my program has been giving me error , not know how solve it:
../lab8.cpp:112:3: error: no matching function call 'getpercentscore' getpercentscore(table[30], key); ^~~~~~~~~~~~~~~ ../lab8.cpp:33:8: note: candidate function not viable: no known conversion 'test *' 'test *' 1st argument double getpercentscore(test *, string key);
any apreciated.
first, try create test array:
test table[30];
at functions.cpp declare function getpercentscore() as:
double getpercentscore(test tbl[], string key)
also, replace reference of table inside getpercentscore() body tbl.
if wish know size of array, pass parameter like:
size_t size = sizeof(table) / sizeof(test); (int i=0;i<studentcount;i++) { double percent=0; getpercentscore(table, size, key); }
hope helped you...
Comments
Post a Comment