Hello!
I'm working on a program that asks for a serial key, checks the input and runs it through an algorithm. To do that I want to convert every character in an array to a number, what's the best way to do that?
I've tried several different ways to solve the problem, but nothing has worked. It was really easy in Python, but very difficult in C++.
To elaborate what I want to do, I can say that I have an array with the whole alphabet in it. I want each character to represent a number.
Atoi didn't work for that.
I'm still trying to understand what you want to do. The kind of information that would be helpful is stuff like:
- how many characters are you going to read in?
- will a character have the same value regardless of position?
- are you going to sum the numeric conversions into a single number, or maintain a list of numbers corresponding to the individual characters read in?
In short, it would be helpful if you'd flesh out the problem for us, along with whatever work you've done so far. We can probably give you better guidance that way.
I'm still trying to understand what you want to do. The kind of information that would be helpful is stuff like:
- how many characters are you going to read in?
- will a character have the same value regardless of position?
- are you going to sum the numeric conversions into a single number, or maintain a list of numbers corresponding to the individual characters read in?
In short, it would be helpful if you'd flesh out the problem for us, along with whatever work you've done so far. We can probably give you better guidance that way.
Sorry, I'll give you an elaboration of my program.
I want each character in an alphabet to have a numerical value, I was thinking of storing them in an array.
Yes, I'm going to sum all the numerical values into a single number.
Here's the code I have so far: http://pastebin.com/wnvu0mFM
Keep in mind that the code is in a very early stage and you can probably find some errors there. Some parts are just there for testing, aswell.
I'm not very experienced with OOP, so there might be some errors with the class and how it's structured. I wouldn't mind tips on how to improve my code though!
static_cast operator works the best :). it needs a good understanding of pointer and class
It seems kind of complicated, aren't there any easier solutions?
well you can certainly can, if you wanted you could have an associative array or a map or you could algorithmically produce the values, all depends on your end goals.