doubling the digits starting from the next-to-last one, yields 18 18 10 8. Adding all digits in these values yields 1 + 8 + 1 + 8 + 1 + 0 + 8 = 27 - Add the sum of the two preceding steps. If the last digit of the resulting sum is 0, the credit card number is valid; otherwise, it is invalid. In our case, 23 + 27 = 50, so the number is valid. Write a C++ program to validate credit card number using the described method. The program should ask the user for an 8-digit credit card number and then print out whether the number is valid or not. The program should repeatedly prompt the user for a credit card number until the user selects to exit the program.
Operations
In mathematics and computer science, an operation is an event that is carried out to satisfy a given task. Basic operations of a computer system are input, processing, output, storage, and control.
Basic Operators
An operator is a symbol that indicates an operation to be performed. We are familiar with operators in mathematics; operators used in computer programming are—in many ways—similar to mathematical operators.
Division Operator
We all learnt about division—and the division operator—in school. You probably know of both these symbols as representing division:
Modulus Operator
Modulus can be represented either as (mod or modulo) in computing operation. Modulus comes under arithmetic operations. Any number or variable which produces absolute value is modulus functionality. Magnitude of any function is totally changed by modulo operator as it changes even negative value to positive.
Operators
In the realm of programming, operators refer to the symbols that perform some function. They are tasked with instructing the compiler on the type of action that needs to be performed on the values passed as operands. Operators can be used in mathematical formulas and equations. In programming languages like Python, C, and Java, a variety of operators are defined.
Assume you are working as a developer in a bank, and you have been asked to develop a program
to validate credit card numbers. Assume also that each credit card number consists of 8 digits. The
following method is used to verify that the credit is valid or not:
- Starting from the rightmost digit, form the sum of every other digit. For instance, if the
credit card number is 43589795, then you form the sum 5 + 7 + 8 + 3 = 23.
- Double each of the digits that were not included in the preceding step. Add all digits of the
resulting numbers. Considering for example the above credit card number 43589795,
doubling the digits starting from the next-to-last one, yields 18 18 10 8. Adding all digits
in these values yields 1 + 8 + 1 + 8 + 1 + 0 + 8 = 27
- Add the sum of the two preceding steps. If the last digit of the resulting sum is 0, the credit
card number is valid; otherwise, it is invalid. In our case, 23 + 27 = 50, so the number is
valid.
Write a C++ program to validate credit card number using the described method. The program
should ask the user for an 8-digit credit card number and then print out whether the number is valid
or not.
The program should repeatedly prompt the user for a credit card number until the user selects to
exit the program.
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images