I'm trying to create a c program that will take in a ten-digit ISBN number and then check to see if the number is valid by calculating its weighted sum. This is the code that I have up to know, but I'm not sure what to do next. Can you give me some pointers? DOCUMENTATION ------------- This program will determine if an ISBN number is valid by calculating its weighted sum. ********************************************************************/ #include #include #define ISBN_SIZE 10 #define MOD_NUM 11 void printInstructions(void); void getIsbn(int isbnArray[]); void printIsbn(int isbnArray[]); int calculateWeightedSum(int isbnArray[]); bool isIsbnValid(weightedSum); void printGoodbye(void); int main() { int isbnArray[ISBN_SIZE] = {0}; printInstructions(); getIsbn(isbnArray); printf("\n\nThe ISBN "); printIsbn(isbnArray); if(isIsbnValid(calculateWeightedSum(isbnArray))) { printf(" is valid."); } else { printf(" is not valid."); } printGoodbye(); return 0; } /******************************************************************************* Shows the user some information about what this program does. *******************************************************************************/ void printInstructions(void) { printf("This program will take in an ISBN number, \n"); printf("and determine if it is valid. "); return; } /******************************************************************************* Gets the ISBN number from the user. *******************************************************************************/ void getIsbn(int isbnArray[]) { int isbnNum; printf("Please enter your ISBN number. \n"); scanf("%d", isbnNum); return isbnNum; } /******************************************************************************* Finds the weighted sum of the ISBN number. *******************************************************************************/ int calculateWeightedSum(int isbnArray[]) { int index, weightedSum = 0; for (index = 0; index < ISBN_SIZE; index++) { weightedSum += (ISBN_SIZE - index) * isbnArray[index]; } return weightedSum; } /******************************************************************************* Checks to make sure that the ISBN number is valid. *******************************************************************************/ bool isIsbnValid(weightedSum) { int getter; getter = (getIsbn % MOD_NUM); return getter; } /******************************************************************************* Shows the user an exit message before the program ends. *******************************************************************************/ void printGoodbye(void) { printf("Thanks for using this program!\n"); printf("Have a great day!\n"); return; }
I'm trying to create a c
DOCUMENTATION
-------------
This program will determine if an ISBN number
is valid by calculating its weighted sum.
********************************************************************/
#include <stdio.h>
#include <stdbool.h>
#define ISBN_SIZE 10
#define MOD_NUM 11
void printInstructions(void);
void getIsbn(int isbnArray[]);
void printIsbn(int isbnArray[]);
int calculateWeightedSum(int isbnArray[]);
bool isIsbnValid(weightedSum);
void printGoodbye(void);
int main()
{
int isbnArray[ISBN_SIZE] = {0};
printInstructions();
getIsbn(isbnArray);
printf("\n\nThe ISBN ");
printIsbn(isbnArray);
if(isIsbnValid(calculateWeightedSum(isbnArray)))
{
printf(" is valid.");
}
else
{
printf(" is not valid.");
}
printGoodbye();
return 0;
}
/*******************************************************************************
Shows the user some information about what this program does.
*******************************************************************************/
void printInstructions(void)
{
printf("This program will take in an ISBN number, \n");
printf("and determine if it is valid. ");
return;
}
/*******************************************************************************
Gets the ISBN number from the user.
*******************************************************************************/
void getIsbn(int isbnArray[])
{
int isbnNum;
printf("Please enter your ISBN number. \n");
scanf("%d", isbnNum);
return isbnNum;
}
/*******************************************************************************
Finds the weighted sum of the ISBN number.
*******************************************************************************/
int calculateWeightedSum(int isbnArray[])
{
int index,
weightedSum = 0;
for (index = 0; index < ISBN_SIZE; index++)
{
weightedSum += (ISBN_SIZE - index) * isbnArray[index];
}
return weightedSum;
}
/*******************************************************************************
Checks to make sure that the ISBN number is valid.
*******************************************************************************/
bool isIsbnValid(weightedSum)
{
int getter;
getter = (getIsbn % MOD_NUM);
return getter;
}
/*******************************************************************************
Shows the user an exit message before the program ends.
*******************************************************************************/
void printGoodbye(void)
{
printf("Thanks for using this program!\n");
printf("Have a great day!\n");
return;
}

Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images









