How would I take just the numeric portions of these calculations and store them as separate variables in a C++ program? How would this be done if the user copy-pasted them all at once?
I know that I would need to treat them as strings...Each of these fields are variable length, and always have 4 decimal places. Beyond that I never really learned this type of logic.
If someone has any type of reading regarding this sort of string separating I would be in love with you <3
Well, in this case that is the way the data is displayed on the website, so excluding the words 'speed' etc to store the variables as "spd" "str""dex" "def" etc would seem to make a lot more sense.
This is just an example too...I'm just wondering how you would get c++ to extract just the numeric data from the string and replicate it for each variable based on the contents of the string.
Assume in the example above that that input was copy-pasted as a single chunk.... It's mind boggling to me.
So, for example, you store some values in a save file for your character. In the save file the contents are as follows:
1 2 3 4
str: 32
spd: 40
dex: 27
def: 16
A really easy way of making it to read in the values would actually be to make strength, speed, dexterity and defense single bytes with different values.
When you reach a new line (when the last character you read in was a newline character '\n'), check for the first byte, and compare it to one of those 4. Then, collect input until you reach the newline character. Then you can use "atoi" for the number input to convert for actual use.
This is just an example too...I'm just wondering how you would get c++ to extract just the numeric data from the string and replicate it for each variable based on the contents of the string.
Assume in the example above that that input was copy-pasted as a single chunk.... It's mind boggling to me.
Maybe you should store all the data in a vector of string. And then process each string.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
// store all strings in a vector.
// for each string
int num = 0;
std::string::iterator it = str.begin();
for ( int power = 0 ; it < str.end(); it++ )
{
// convert char to number by subtracting '0'
// and then multiply by power of 10
num += (*(it) - '0' ) * pow( 10.0f , power );
power ++ ; // increase power
}