#include <conio.h>
#include <iostream>
#include <cstring>
#include <ctype.h>
using namespace System;
using namespace System::String;
enum CardType{
MasterCard,
BankCard,
Visa,
AmericanExpress,
Discover,
DinersClub,
JCB
};
bool Validate(CardType cardType, String cardNumber){
int number[16], len=0;
for(int i=0; i<strlen(cardNumber); ++i){
cardNumber[i] = atoi(cardNumber[i]);
if(isdigit(cardNumber[i])){
if(len == 16) return false;
number[len++] = cardNumber[i];
}
}
switch(cardType){
case CardType.MasterCard:
if(len!=16) return false;
if(number[0] != 5 || number[1] == 0 || number[1] > 5)
return false;
break;
case CardType.BankCard:
if(len != 16)
return false;
if(number[0] != 5 || number[1] != 6 || number[2] > 1)
return false;
break;
case CardType.Visa:
if(len != 16 && len != 13)
return false;
if(number[0] != 4)
return false;
break;
case CardType.AmericanExpress:
if(len != 15)
return false;
if(number[0] != 3 || (number[1] != 4 && number[1] != 7))
return false;
break;
case CardType.Discover:
if(len != 16)
return false;
if(number[0] != 6 || number[1] != 0 || number[2] != 1 || number[3] != 1)
return false;
break;
case CardType.DinersClub:
if(len != 14)
return false;
if(number[0] != 3 || (number[1] != 0 && number[1] != 6 && number[1] != 8)
|| number[1] == 0 && number[2] > 5)
return false;
break;
case CardType.JCB:
if(len != 16 && len != 15)
return false;
if(number[0] != 3 || number[1] != 5)
return false;
break;
}
//Using the Luhn's Algorithm
int sum = 0;
for(i=len-1; i>=0; ++i){
if(i % 2 == len % 2){
int n = number[i] * 2;
sum += (n / 10) + (n % 10);
}
else
sum += number[i];
}
return (sum % 10 == 0);
}
void valid(){
cout << "The credit card number is VALID !";
}
void invalid(){
cout << "The credit card number is INVALID !";
}
int main(){
system("cls");
string ccn, ct;
cout << "Enter the Card Type :";
cin >> ct;
cout << "Enter the Credit card Number :";
cin >> ccn;
CardType card = ct;
bool val = Validate(ct, ccn);
if (val == true) valid();
else invalid()
getch;
return 0;
}
There are a lot of errors ..... !
Please help me correct them ....
How do declare a string in Visual C++ ?
Is it not same as in C# ... like "string s;" !!!????
:confused: