Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main() {
- string card;
- int digit, sum = 0, alternate = 0;
- cin >> card;
- for (int i = card.length() - 1; i >= 0; i--) {
- digit = card[i] - '0'; //int cast convert digit to integer
- if (alternate == 1)
- digit = digit * 2;
- sum = sum + digit / 10;
- sum = sum + digit % 10;
- alternate = !alternate;
- }
- if (sum % 10 == 0) {
- if (card[0] == '4' && card.length() >=13 && card.length()<= 16) {
- cout << "Visa";
- }
- else if (card[0] == '5' && card[1]>='1' && card[1]<='5' && card.length() == 16) {
- cout << "Mastercard";
- }
- else if (card[0] == '3' && (card[1]=='4' || card[1]=='7') && card.length() == 15) {
- cout << "Amex";
- }
- else {
- cout << "Almost";
- }
- }
- else {
- cout << "Invalid";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement