Im trying to call a function from a class called report but i cannot call i have tried calling it like this Candidate::report(output,x),Candidate rep; rep.report; and none of the seem to be working any help would be greatly appreciated
/**
* Print the report line for the indicated candidate
*/
void report (std::ostream& out, int totalDelegatesAllStates);
};
#endif
cpp file for header
#include "candidates.h"
#include "states.h"
#include <iostream>
using namespace std;
Candidate::Candidate (string candidateName)
{
name = candidateName;
delegatesWon = 0;
}
/**
* Print the report line for the indicated candidate
*/
void Candidate::report (ostream& out, int totalDelegates)
{cout<<"try";
int requiredToWin = (2 * totalDelegates + 2) / 3; // Note: the +2 rounds up
if (delegatesWon >= requiredToWin)
out << "* ";
else
out << " ";
out << delegatesWon << " " << name << endl;
} main function
int main(int argc, char** argv)
{
// Main routine - if command parameters give two filenames,
// read from the first and write to the second. If not,
// read from standard input and write to standard output
if (argc == 3)
{cout<<"yeah";
ifstream in (argv[1]);
ofstream out (argv[2]);
primaryElection (in, out);
}
else
primaryElection (cin, cout);
Check the arguments in the calling function "primaryFunction" in this block:
1 2 3 4 5 6 7 8
if (argc == 3)
{cout<<"yeah";
ifstream in (argv[1]);
ofstream out (argv[2]);
primaryElection (in, out);
}
else
primaryElection (cin, cout);
Also, in the definition of "report function", you are passing "0" as a value for "totalDelegate". delegateWon already is initialized to "0" and nothing is changing its value so the condition if (delegatesWon >= requiredToWin)
will always be false except when requiredToWin is "0"
1 2 3 4 5 6 7 8 9 10
void Candidate::report (ostream& out, int totalDelegates)
{cout<<"try";
int requiredToWin = (2 * totalDelegates + 2) / 3; // Note: the +2 rounds up
if (delegatesWon >= requiredToWin)
out << "* ";
else
out << " ";
out << delegatesWon << " " << name << endl;
}