Need help with error message.

Im writing a program that reads credit card numbers and tells you whether they are valid or invalid cards. Im getting some error message and am not sure how to fix or rewrite it. Lines 34 and 43 i get error"implecite conversion loses integer percision: 'unsigned long' to int'.
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#include<iostream>
#include<sstream>
#include<string>
#include<cmath>

using namespace std;

bool creditCardType(string cardNumber)
{
    return
    //For Visa cards
    (cardNumber.compare(0, 1, "4") == 0) ||
    //For Mastercards
    (cardNumber.compare(0, 1, "5") == 0) ||
    //For American Express card
    (cardNumber.compare(0, 2, "37") == 0) ||
    //For Discover cards
    (cardNumber.compare(0, 1, "6") == 0);
}
int getDigit(int number)
{
    int result =0;
    while(number)
    {
        result = result + (number%10);
        number = number/10;
    }
    return result;
}
// to calculate sum of numbers at even places.
int sumOfDoubleEvenPlaces(const string& cardNumber)
{
    int sum_even_places = 0;
    for (int i = cardNumber.length() -2; i>=0; i-=2)
    {
        sum_even_places = sum_even_places + getDigit(2*(cardNumber[i] - '0'));
    }
    return sum_even_places;
}
int sumofoddplace(const string& cardNumber)
{
    int sum_odd_places = 0;
    for (int i = cardNumber.length() -1; i>=0; i-=2)
    {
        sum_odd_places = sum_odd_places +((cardNumber[i] - '0'));
    }
    return sum_odd_places;
}
// function to check card is valid or not.
bool isValid(const string& cardNumber)
{
    return ((sumOfDoubleEvenPlaces(cardNumber)+sumofoddplace(cardNumber))%10==0);
}
//Write a program that prompts the user to enter a credit card number as a long integer.
int main()
{
    long int cardnNum;
    int choice;
    cout << "Please enter your credit card number: ";
    cin >>cardnNum;
    cout << endl;
    stringstream ss;
    ss << cardnNum;
    string cardnumber = ss.str();
    // You program will begin by asking the user what type of execution:
    // 1= use asset logic on length of credit card number
    // 2= print error message and continue on to next credit card number.
    //Display the credit card number, length of credit card number and whether the number is valid or invalid.
    cout <<"Press 1 to use asset logic on length of credit card number" << endl;
    cout <<"Press 2 to use creditCardType logic on credit card number " << endl;
    cin >> choice;
    if(choice == 1)
    {
        cout << cardnumber << " is a ";
        if(cardnumber[0] == '4')
            cout <<" VISA";
        if(cardnumber[0] == '5')
            cout <<" MASTER";
        if(cardnumber[0] == '6')
            cout <<" DISCOVER";
        if(cardnumber[0] == '3')
            cout <<" AMERICAN EXPRESS";
        cout << endl;
        if((cardnumber.length()>=13 && cardnumber.length()<=16))
            cout << cardnumber << " has a length of " <<cardnumber.length() <<" is a valid card " << endl;
        else
            cout << cardnumber<< " has a length of " <<cardnumber.length() <<" is an invalid card " << endl;
    }
    else if(choice == 2)
    {
        if(creditCardType(cardnumber) && isValid(cardnumber))
        {
            cout << cardnumber << " is a ";
            if(cardnumber[0] == '4')
                cout <<" VISA";
            if(cardnumber[0] == '5')
                cout <<" MASTER";
            if(cardnumber[0] == '6')
                cout <<" DISCOVER";
            if(cardnumber[0] == '3')
                cout <<" AMERICAN EXPRESS";
            cout <<" Is Valid card " << endl;
        }
        cout << cardnumber << " has invalid type so "<< cardnumber<<" is an invalid card " << endl;
    }
    system("pause");
    return 0;
}
Maybe cause of your compiler.
You may try size_t instead of int.
No it doesnt work. Error still there.
Are you sure it is an error and not a warning? Also the length function returns a std::size_t which is in your case a unsigned long instead of an int. It shouldn't give you any errors but maybe a warning.
Topic archived. No new replies allowed.