Need some help with strings

I'm having to write a program for class which verifies if a number is a ISBN-13 number. The formula to check if a number is a ISBN-13 is illustrated here
10 –((1*9+ 3*7+ 1*8+ 3*1+ 1*5+3*8+ 1*0+ 3*8+ 1*9+ 3*2+ 1*7+ 3*9)% 10) == 7 Each of the first 12 digits were multiplied by cycling 1 and 3, then added together, divide the summation by 10, and subtract the remainder from 10.I can't seem to figure out what I'm doing wrong in my code and some help would really be appreciated.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
  #include <iostream>
#include <string>
using namespace std;

string str;
bool is_isbn_13_valid (string str)
{
	for (int i = 0; i < str.length(); i++)
	{
		str[i] = str[i] - '0';
		
	}
	for (int x = 0; x < str.length(); x++)
	{
		if (x%2 == 0)
		{
			str[x] = str[x]*1;
		}
		else
		{
			str[x] = str[x]*3;
		}
	
	}
	if ((10-((str[0]+str[1]+str[2]+str[3]+str[4]+str[5]+str[6]+str[7]+str[8]+str[9]+str[10]+str[11])%10)) == str[12])
	{
		return true;
	}
	else
	{
		return false;
	}
}

int main()
{
	cout << "Enter a number to check if it is a ISBN-13 number: ";
	cin >> str;
	is_isbn_13_valid(str);
	if (is_isbn_13_valid)
	{
		cout << "It is a ISBN-13 number";
	}
	else 
	{
		cout << "It is not a ISBN-13 number"; 
	}
}

No matter what I do the value always returns as true for some reason and I'm not sure why. I think it is because I'm not actually converting the numbers in the string to an integer data type but I don't know how to fix it.
Last edited on
Line 39,40: That's not how to call a bool function. Line 40 is testing the function address of is_isbn_13_valid, which is always going to be true.

40
41
//  Correct way to call a bool function
if (is_isbn_13_valid(str))



Thanks a lot! Its working perfectly now.
Topic archived. No new replies allowed.