Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Luhn algorithm for C++

Status
Not open for further replies.

CyberOps

Programmer
Sep 26, 2000
1
US
Hi,

I'm trying to convert a luhn algorithm from C to C++. Here is what I have. I'm having a problem with the main function. I'm not sure where to put it. Here is the code and the compile errors.
Thanks

#include<string.h>

static int verify_checksum(char *credit_card)

{
char *cp;
int dbl;
int check_sum;

check_sum = 0;
dbl = 0;
cp = credit_card + strlen(credit_card) -1;
while (cp >= credit_card)

{

int c;

c = *cp-- -'0';

if (dbl)
{
c *= 2;
if (c >= 10)
c -= 9;
}

check_sum += c;
dbl = !dbl;

}
return ((check_sum % 10) == 0);
}


//eof



Linking...
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/ccver.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

ccver.exe - 2 error(s), 0 warning(s)
[sig][/sig]
 
That function seems fine and should run in C++, but where is your void main() function? if this is a console app.
[sig]<p>Karl<br><a href=mailto:kb244@kb244.com>kb244@kb244.com</a><br><a href= </a><br>Experienced in : C++(both VC++ and Borland),VB1(dos) thru VB6, Delphi 3 pro, HTML, Visual InterDev 6(ASP(WebProgramming/Vbscript)<br>
[/sig]
 
Hi Karl,

Thanks for the reply. That is my problem, I'm not sure where to put the main() function. The program compiles okay, but the errors above is when it is building. I'm not sure where to implement the main function.
Thanks,
Sean
 
in most C++ Console programs you have

[tt]
your include statements, like you have

the list of your functions besides main (or you can use function prototypes to type in the function after main)

int myfuync(var); <--- example of func prototype, just lets compiler know there is a functino named this after main.

void main()
{
This is where your program starts, so whatever you want to start up in your program, you call from inside here.
}

The rest of your functions (if you used function prototypes)
[/tt]

of course it is possible to make main return a value, but most C++ programs keep the main routine voided, so no return is nessary. [sig]<p>Karl<br><a href=mailto:kb244@kb244.com>kb244@kb244.com</a><br><a href= </a><br>Experienced in : C++(both VC++ and Borland),VB1(dos) thru VB6, Delphi 3 pro, HTML, Visual InterDev 6(ASP(WebProgramming/Vbscript)<br>
[/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top