#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
using namespace std;
int main()
{
int count;
int creditcard_number, digit, digit2, sum;
int credit1,credit2,credit3,credit4,credit5,credit6;
count = 0;
ifstream myfile;
myfile.open ("CreditCards.txt");
if(!myfile.fail())
{
__int64 credit1, credit2, credit3, credit4, credit5, credit6;
double creditcard_number;
myfile>>credit1>>credit2>>credit3>>credit4>>credit5>>credit6;
cout << credit1<<credit2<<credit3<<endl;
}
else
{
cout<< "Couldn't read file"<<endl;
}
while (myfile>>credit1>>credit2>>credit3>>credit4>>credit5>>credit6)
{
count++;
digit = creditcard_number % 10;
if (digit % 2== 0 )
{
digit2 = digit *2;
if (digit2 >9)
{
sum += 1+ digit2 %10;
}
else
{
sum+= digit2;
}
else
{
sum += digit;
creditcard_number /=10;
}
}
myfile.close();
return 0;
You'll still have to troubleshoot this. I cleaned up your code, got rid of what it looked like wasn't necessary, etc.
Does your compiler support '__int64' or 'long long' declarations? Or do you actually need to do some bit-shifting magic?
Anyways, this is a start.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
#include <iostream>
#include <fstream>
using namespace std;
int main(){
int count = 0;
float digit, digit2, sum;
__int64 c1, c2, c3, c4, c5, c6;
double ccNum;
ifstream myfile;
myfile.open ("CreditCards.txt");
if(myfile.fail()) return 0;
myfile>> c1 >> c2 >> c3 >> c4 >> c5 >> c6;
cout << c1 << c2 << c3 << c4 << c5 << c6 << endl;
while (myfile >> c1 >> c2 >> c3 >> c4 >> c5 >> c6) {
count++;
digit = ccNum % 10;
if (digit % 2 == 0){
digit2 = digit * 2;
if (digit2 > 9) sum += (1 + digit2) % 10;
else sum += digit2;
}
else{
sum += digit;
ccNum /= 10;
}
}
myfile.close();
return 0;
}
|
Last edited on
Thanks sorry for taking so long to respond I was about to figure it out :]