Jump to content

Trying to make a hash function that will take in a name and convert it to ASCII (with a random variable on the end) 

 

#include <iostream>
#include <string>
using namespace std;
 
int hasher(string name)
{
int integer;
    for (int counter = 0; counter >= name.length(); counter++)
    {
        integer = integer + ((int)name[counter] * counter);
    }
    cout << integer;
}
 
int main ()
{
    string name;
    cout << "Input your name";
    cin >> name;
    hasher(name);
}
 
 
Any idea where ive gone wrong and get the same number for any name i put in??
 
Thanks 
Link to comment
https://linustechtips.com/topic/329817-issue-with-my-hash/
Share on other sites

Link to post
Share on other sites

hasher function should look like this:

 

int hasher(string name){    int integer = 0;    for (int counter = 0; counter < name.length(); counter++)    {        integer = integer + ((int)name[counter] * counter);    }    cout << integer;    return integer;}

"Only two things are infinite, the universe and human stupidity, and I'm not sure about the former."


- Albert Einstein

Link to comment
https://linustechtips.com/topic/329817-issue-with-my-hash/#findComment-4506096
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×