Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

In addition to my previous post on the 1dimensional array 1

Status
Not open for further replies.

iamjd

Technical User
Feb 12, 2005
37
US
The following code should take the isbnSum variable and divide is by 11 and if the answer is evenly divided then it should return 1 to the isValid boolean.

I am not sure on what technique or approach I should take in order to do so. Can someone possibly point me in the right direction?

Code:
#include <stdafx.h>

int isbn[10];

int main()
{
	bool isValid;
	int isbnSum=0;
	int i;

	for (i=0;i<10;i++)
	{
		printf("Enter digit # %d of isbn number.\n", i + 1);
		scanf("%d", &isbn[i]);
	}

	for (i=0;i<10;i++)
	{	
		isbnSum += isbn[i];
	}

	isValid = (isbnSum / 11);

	if(isValid)
	printf("isbn is valid.\n");
	else
	printf("isbn is invalid\n");

	return 0;
}
 
Try this
Code:
isValid = (isbnSum % 11) == 0;
This is one way of checking whether isbnSum is divisible by 0. The modulo operator % can be thought of as the remainder. It is not a proper modulo function: not mathematically anyway but for what you're doing, it should be OK.
 
xwb, sorry to be really stupid about this, but I'm definitely a bit mathematically challenged: what's the difference between the remainder of an integer division as given by % and a proper mathematical modulus? I always assumed they were the same.
Thanks in advance...
 
iamjd, as I remember, the last digit of ISBN is a control one and is a 11-basis digit, accepting values 0..9 and 'X', concerning to be value 10. Therefore simply scanf() will not work, you should input it as string or character and then evaluate.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top