hi evrybdy....
how can i generate a unique code against the user input in c++...

Recommended Answers

All 7 Replies

You should rephrase that.
What do you want to do exactly?

a program in c++ which take some string from user and generate a unique code against it

I will explain in sudo code for now.. But if you need assistance I will help you out.. But what I would do, (Which is not always the best thing), is use a loop with a function.. use a loop to go through the length of the word.. if the letter is an A than return an F (for example).. and repeat the if then statement until all the letters you want to use are complete.. then make another function to convert it back to normal.. If you want to use numbers.. Id use 2 digits.. For example: A = 15..

a program in c++ which take some string from user and generate a unique code against it

Thats called hashing. You could do something like this :

string str = "abc";
unsigned long long hashCode =  str[0]*1 + str[1]*2 + str[2]*3;

Basically, you are multiplying the value at the string's position by its index plus 1.

If you want something better, google the term hash function.

> Thats called hashing.
Hashing is not guaranteed to produce unique codes except in special circumstances. The answer to this question really depends on what the code is used for. The needs of the program determine how the code is generated. For example, if the code is unique for each user, the code needs to be salted with identifying information about the user to get around two users typing the same string.

Is this thread solved?? Do you still have trouble?? Are you trying to create a function to use as a cipher??

learn about data bases and indexing possibly.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.