Before reading this problem please note that this is a PRACTICE problem for hp codewars (a programming competition), I am not asking the forum about a real problem. My program is supposed to take the following input:
-a number that represent the number of candies in a jar
-the number of guesses that the user will be entering in
-a person's name, followed by a space and then their guess
ex:
422 ----------------- amount of candies in jar
2 -------------------- number of guesses
joe 324 -------------name of guesser and their guess of how many candies are in the jar
mary 435 ----------second guesser and guess
The output should be the name of the person who had the closest guess
ex:
mary
I am currently coding the function that returns the closest number to the guess. However when I run the code, it gives me the error "no match for call '(std::vector) (int)" on two lines. The lines that are sending back errors are pointed out in comments in my code.
Here is my code:
vector<int> compare(vector<int> nums, int loopnum, int ans)
{
vector<int> buff2;
for (int i = 0; i<loopnum;i++)
{
vector<int>diff;
int buff = ans - nums.at(i);
for (int j = 0; j<loopnum; j++)
{
diff.push_back(buff);
for (int k = 0; k<diff.size(); k++)
{
if (k == 0)
{
buff2.push_back(diff.at(k));
}
else
{
if ((abs(buff2(0))) > abs(diff.at(k))) // this line is sending back an error
{
buff2.clear();
buff2.push_back(diff.at(k));
}
else if ((abs(buff2(0))) == abs(diff.at(k))) // this line is also sending back an error
{
buff2.push_back(diff.at(k));
}
}
}
}
}
return buff2;
}
Please help me fix this!
Aucun commentaire:
Enregistrer un commentaire