Click here to Skip to main content
15,887,936 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I don't understand why I am getting this error.
Here is my code.

#include<iostream>
#include<string>
#include<fstream>
#include<iomanip>
#include<stdlib.h>


using namespace std;

enum CCType{ VISA, MASTERCARD, INVALID };
int const LINEMAXIMUM = 60;
int const CCNUMBERLENGTH = 16;

CCType validate (string aCreditCardNumber);

int main ()
{
	ifstream myIn;
	string aCreditCardNumber;
	float amount;
	string filename;
	string VISA[LINEMAXIMUM];
	string MASTERCARD[LINEMAXIMUM];
	string INVALID[LINEMAXIMUM];
	float VISAamt[LINEMAXIMUM];
	float MASTERCARDamt[LINEMAXIMUM];
	float INVALIDamt[LINEMAXIMUM];
	CCType type;
	CCType Cardtype;
	
	int l=0;
	int m=0;
	int n=0;
	
	
	cout <<"What is the name of the file"<< endl;
	cin >>filename;
	myIn.open("dataset.txt");
	
	while (filename!="dataset.txt")
	{	
	cout <<"File does not exist"<<endl<<"What is the name of the file"<<endl;
	cin >> filename;
	}
	
	while (myIn)
		
	{  
		myIn >> aCreditCardNumber >> amount;
		//Cardtype = validate(aCreditCardNumber);
		if (Cardtype == VISA)
		{
			VISA[l]=aCreditCardNumber;
			VISAamt[l]=amount;
			l++;
		}
		if (Cardtype == MASTERCARD)
		{
			MASTERCARD[m]=aCreditCardNumber;
			MASTERCARDamt[m]=amount; 
			m++;
		}
		if (Cardtype == INVALID)
		{
			INVALID[n]=aCreditCardNumber;
			INVALID[n]=amount;
			n++;
		}
		
	}
	myIn.close();
	

	
	
	
	
	
	
	
	
	
return 0;
}	
CCType validate (string aCreditCardNumber)
{	CCType type;	bool checknum = true;
	int sumi=0;
	int sumj=0;
	int ccdigit=0;
	int jnum=0;
	int sumij=0;
	int credit[15];
	
		for (int i=1; i<=15; i=i+2)
			{ sumi= (aCreditCardNumber[i] - '0') + sumi;
			}
		for (int j=0; j<=15; j=j+2)
		{	jnum=(aCreditCardNumber[j] - '0') * 2;
			if (jnum<10)
			{	sumj= jnum+ sumj;
			}
		
			 else  sumj=((jnum%10)+1)+sumj;
		}	
			sumij=sumj+sumi;
			if (sumij%10!=0)
				checknum==true;
			if (sumij%10 !=0 || aCreditCardNumber.size()>16)
			{	checknum==false;
				
			}
			if (checknum==true)
			{
				if (aCreditCardNumber[0]=='4')
				type = VISA;
		
				else if ((aCreditCardNumber[0]=='5') && (aCreditCardNumber[1]=='1' || '2' || '3' || '4' || '5'))
					type = MASTERCARD;
				
			
				else type = INVALID;
			}
return type;
}
Posted
Updated 17-Sep-10 12:16pm
v2
Comments
HimanshuJoshi 17-Sep-10 18:16pm    
Added Code block

Hi,
Your VISA etc.. identifiers are ambiguous.
Change the enum identifiers to
C++
enum CCType{ e_VISA, e_MASTERCARD, e_INVALID };

and use them where relevant, for instance:
C++
if (Cardtype == e_VISA)
{
    VISA[l]=aCreditCardNumber;
    VISAamt[l]=amount;
    l++;
}

Your code will compile without error, still far from operational.
cheers,
AR
 
Share this answer
 
Thanks it does compile but it still needs work but i appreciate your help.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900