I am trying to create hashing function the algorithm requires me to take each letter of the string and converting it to ascii, multiply it by a number based on its position in the string (for example Input is STACK; ascii for S would be 344 multiply that value by 9^9 then ascii for T would be 347 multiply that value by 8^8.. etc), and then add the values together.
I understand how to access the values in the array to create the sum and can convert to ASCII. I don't understand how i would access the array to perform the calculations in-between.
my code is below :
#include <iostream>
#include <string>
using namespace std;
int main()
{
string input ;
int finalanswer = 0;
cout << "Enter your first name please : " ;
cin >> input;
cout << "Your name is " << input ;
for (int x=0; x < input.size(); x++)
{
finalanswer += input[x];
cout << finalanswer ;
}
cin.get();
return 0;
}