Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid number of arguments! Usage: set_solver <puzzle_file> #1

Open
jhworth8 opened this issue Sep 13, 2020 · 2 comments
Open

Invalid number of arguments! Usage: set_solver <puzzle_file> #1

jhworth8 opened this issue Sep 13, 2020 · 2 comments

Comments

@jhworth8
Copy link

Hello! Great work on this.
When I run the code in Visual Studio, the output is "Invalid number of arguments!
Usage: set_solver <puzzle_file>"

I am a beginner programmer and not sure why it is saying that because the code looks good. Thanks!

@abhijitvalluri
Copy link
Owner

You need to provide it an argument, namely a puzzle file for it to solve the problem.

The format of the puzzle file needs to be similar to this: https://github.com/abhijitvalluri/set-solver/blob/master/advanced1.txt

@jhworth8
Copy link
Author

Thank you very much, and for the quick response. Would that mean changing the name of "puzzle" here?
int main (int argc, char* argv[]) {

if (argc != 2) {
    std::cerr << "Invalid number of arguments!\n"
              << "Usage: set_solver <puzzle_file>" << std::endl;
    return 1;
}

std::fstream puzzle(argv[1], std::ios::in);
if (!puzzle.is_open())  {
    std::cerr << "Unable to open puzzle file" << std::endl;
    return 2;
}

std::vector<Card> cards;
try {
    cards = getCardsFromInput(puzzle);
} catch(InputError& e) {
    std::cerr << "Error while reading input: " << e.what() << std::endl;
    return 3;
}

std::vector<Set> sets = getAllSets(cards);

for (size_t i = 0; i != sets.size(); ++i) {
    std::cout << "Set #" << i << " " << sets[i].toString() << std::endl;
}

return 0;

}

Sorry, I am a beginner. I enjoy learning, by doing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants