Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.
C++ ISBN check few question
Hello, we have a competition in our school and our target is to design (in any language you want, I have choosen C++ because I don't know any other) a program which will check the ISBN. For those who don't know what the ISBN is, then, the ISBN is number which identifies a book. The program must check if the ISBN is valid. So far, I have a basic string-parsing function, which looks like this:
#include <vector>
#include <string>
#include <iterator>
#include <algorithm>
using namespace std;
int main()
{
cout << "Enter the ISBN code >> ";
string isbn_code;
const string delim = " -";
getline (cin, isbn_code);
string::size_type start_idx = 0;
string::size_type end_idx = isbn_code.find_first_of(delim);
vector<string> strCodes;
while (end_idx != string::npos)
{
strCodes.push_back(isbn_code.substr(start_idx, end_idx-start_idx));
start_idx = end_idx+1;
end_idx = isbn_code.find_first_of(delim, start_idx);
}
copy(strCodes.begin(), strCodes.end(), ostream_iterator<string>(cout, "\n"));
return 0;
}```
What this function does is separating user input. The user will enter for example "ISBN 80-85479-10-9" and the program will return if it is valid. The ISBN check algorithm exists, and I'm planning to include it into my program. Basically all I need is to perform some basic math operations with this, and then compare it. My problem is, that the code I've written is not working correctly. First I need to separate EACH number, ISBN on the begin too, of course. With these numbers I'll then perform the operation. But, the problem is that this code separates the input with characters declared in the 'delim' stringl. It's a space and a '-'. And if I'll enter "ISBN 80-85479-10-9" the vector is then only ISBN 80 85479 10 and the last number, 'check character' sorry I don't know the right English world for it is not displayed. I need better function. Any suggestions? Thanks in advance for any help.