Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The last digit of a credit card number is the check digit, which protects agains

ID: 3664187 • Letter: T

Question

The last digit of a credit card number is the check digit, which protects against transcription errors such as an error in a single digit or the transposition of two adjacent digits. The following method is used to verify actual credit card numbers but (for simplicity) we will describe it for a number with 8 digits instead of 16. Starting form the rightmost digit, form the sum of every other digit. - Example: if the card number is 4358 9795, then you form the sum: 5 + 7 + 8 + 3 = 23 Double each of the digits that were not included in the previous step. Add all the digits of the resulting numbers. - Example: for the card number 4358 9795, the not included digits were [9, 9, 5, 4]. Doubling these leads to [18, 18, 10, 8j. Summing the digits results in: 1 + 8 + 1 + 8 + 1+ 0 + 8 = 27 Add the sums from the previous two steps. If the last digit of the sum is zero, then the credit card number is valid. - Example: for the number 4358 9795, this step gives 23 + 27 = 50. The last digit of 0 means the number is valid. Write a program that accepts a number from the user via a prompt and perform the above algorithm to check if the number is valid or not. If the number is valid, print a message to the screen informing the user. Your program should be capable of performing the algorithm on a number consisting of any number of digits. The output of your program should display the credit card number entered and its validity status. For example: 43589795 is a VALID credit card number. Test your program with the following numbers (spaced provided simply to make reading easier, your program does not need to handle spaces.):

Explanation / Answer

#include <iostream>

using namespace std;

//main method

int main()

{

int number,i;

cout<< ”enter the credit card number:”<< end1;

cin>>number;

int sum1=0;sum2=0,test,num;

test=number;

for(i=0;i<8;i++)

{

num=test%10;

test=test/10;

if(i%2==0)

{

sum1=sum1+num;

}

}

int digit;

test=number;

for(i=0;i<8;i++)

{

num=test%10;

test=test/10;

if(i%2==1)

{

num=num*2;

while(num!=0)

{

digit=num%10;

num=num/10;

sum2=sum2+digit;

}

}

}

if((sum1+sum2)%10==0)

{

cout<<”credit card number is valid ”;

}

else

{

cout<<card is not valid..check your number”<<end1;

}

system(“pause”);

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote