Can someone please help me with how to resolve this issue? It says I have 2 unresolved externals where the problem is in the function "int calculations()". Here are the two errors from Visual Studio:
Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol "int __cdecl sumOfEvenPlace(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?sumOfEvenPlace@@YAHABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function "int __cdecl calculations(void)" (?calculations@@YAHXZ) ConsoleApplication32 c:\Users\Jawad\documents\visual studio 2015\Projects\ConsoleApplication32\ConsoleApplication32\Source.obj 1
Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol "int __cdecl sumOfOddPlace(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?sumOfOddPlace@@YAHABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function "int __cdecl calculations(void)" (?calculations@@YAHXZ) ConsoleApplication32 c:\Users\Jawad\documents\visual studio 2015\Projects\ConsoleApplication32\ConsoleApplication32\Source.obj 1
creditCard.substr(0, 1); //takes the first number of a string
if (creditCard == "4") {
ccType = "Visa"; //first number is 4 means Visa card
}
if (creditCard == "5") {
ccType = "Mastercard"; //first number is 5 means Mastercard
}
if (creditCard == "3") {
ccType = "American Express"; //first number is 3 means American Express
}
if (creditCard == "6") {
ccType = "Discover"; //first number is 5 means Discover card
}
return 0;
}
int calculations() {
int ccNumber = std::stoi(creditCard); //converts string to an integer
int sumOfOddPlace(const string& creditCard); //formula for adding odd places
{
int result = 0;
for (int i = creditCard.size() - 1; i >= 0; i = i - 2)
{
result += ((creditCard[i] - '0')* 2);
}
return result;
}
int sumOfEvenPlace(const string& creditCard); //formula for adding even places
{
int result = 0;
for (int i = creditCard.size() - 2; i >= 0; i = i - 2)
{
result += ((creditCard[i] - '0') * 2);
}
return result;
}
if ((sumOfEvenPlace(creditCard) + sumOfOddPlace(creditCard)) % 10 == 0)
{
cout << "Credit Card is valid" << endl;
}
PLEASE ALWAYS USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post. http://www.cplusplus.com/articles/jEywvCM9/ http://www.cplusplus.com/articles/z13hAqkS/
Hint: You can edit your post, highlight your code and press the <> formatting button.
You can use the preview button at the bottom to see how it looks.
Lines 59 and 72 are very nice proto types and should not be there and should be above main with the others. if you remove the semicolon from the end of the line they become functions which should not be in the "calculations" function.
Line 97 not the best name for a function. It is to easy to confuse "main1" with "main" as I did.
Other than line 6 being a bad idea and should not be used. I will have to look at the program more in depth tomorrow.