check validation of Isbn number

isbn
Last edited on
Read the documentation.

http://www.cplusplus.com/reference/iostream/istream/getline/

getline takes a char* and a size. What are you trying to pass it? An int*.

Weighted Sum = 110

Since the weighted sum calculated = 110, the weighted sum modulus 11 is therefore zero, it a valid isbn
Last edited on
You missed the point entirely.

getline does NOT take an int*. You are trying to feed it an int*.

Here, see this line of code:
cin.getline(num,10); num should be a char*. It is not. Do you understand?
OP for reference:

hey anybody help,this is freezing my mind. i suppose to write a program wich takes 10 digits including 'X' some time from the user and check the validation of isbn dividing by 11.i try a program but dosent take number from user.pleas help.

#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <cstring>
using namespace std;

int main()

{






const char*str;

int num[10];
int check = 0, i,val = 0, mod = 1, length = 0;

cout<<"enter the isbn number"<<endl;
cin.getline(num,10);

if (str == NULL)
check = 0;




else if (strlen(str) == 10) //10 characters in the string
{
check = 1;
for (i = 0; i < 9; i++) //go through first 9 characters, make sure they're a digit. If they are valid, propagate num array with numerical values
{
if (str[i] < '0' || str[i] > '9')
check = 0;


else
num[i] = str[i] - '0';




}


if (check != 0) //the first 9 characters are digits, make sure 10th char is either a digit or letter X (10). Propagate 10th num array position with numerical value.
{
if (str[9] < '0' || str[9] > '9' && str[9] != 'X')


check = 0;


else if (str[9] == 'X')
num[9] = 10;






else
num[9] = str[9] - '0';


}


if (check != 0) //do the math to make sure it's all modulo 11
{


for (i = 0; i < 10; i++)
{

val += num[i] * (10 - i);
}


mod = val % 11;




if (mod != 0)
check = 0;
}


} // if statement about there being 10

system("pause");
return check;
}


and original reply, for reference:

yes i was take a set of number eg 0070216045
Code Weight Weighted Value
0X10 = 0
0x9 = 0
7x8 = 56
0x7 = 0
2x6 = 12
1x5 = 5
6x4 = 24
0x3 = 0
4x2 = 8
5x1 = 5
Weighted Sum = 110

Since the weighted sum calculated = 110, the weighted sum modulus 11 is therefore zero, it a valid isbn
Topic archived. No new replies allowed.