Hey guys. I'm working on a class assignment and I'm having trouble converting a string - "Bread" for example, to a unique numerical value - 529384002 for example.
I would assume it's not terribly difficult, but I'm relatively new to C++ and Google hasn't been helpful.
#include <iostream>
#include <string>
int main()
{
std::string myString;
long randomizer = 100;
std::cout << "Enter a string: ";
std::getline(std::cin, myString);
// Converts each character of string into an integer
// and adds them together
for (int i = 0; i < myString.size(); i++)
{
randomizer += myString[i];
}
// Make our number a little bit more unique
randomizer *= 3.1415;
randomizer += myString.size() * (int)myString[0];
randomizer *= (int)myString[myString.size() - 1];
std::cout << "Your strings unique number is: " << randomizer << std::endl;
return 0;
}