warning: pointer to a function used in arithmetic
error: ISO C++ forbids comparison between pointer and integer
warning: pointer to a function used in arithmetic
error: invalid operands of types ‘void(int&, int&, int&, int&, int&, int&)’ and ‘int’ to binary ‘operator*’
error: in evaluation of ‘operator*=(void(int&, int&, int&, int&, int&, int&), int)’
Go ahead and say it's horrible code but at least correct me :)
Thanks in advance.
There's an error in the logic in your for loop. the "else if (i == 6)" may never get called when it should, and it indexes out-of-range memory which could cause a segfault. Second problem, "i" is out of scope when you use it in the if statement at the end of the loop. I would suggest a solution but it's probably best to just re-write it entirely.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
int attributes[6];
for (int i = 0; i < 6; ++i) attributes[i] = (rand() % 15) + 3; //use a for loop!, 6 less lines
int str = 0;
bool str_valid = false;
do {
cout << "Assign Strength: " << endl;
cin >> str;
for (int i = 0; i < 6; ++i) {
if (str == attributes[i] && attributes[i] != 0) {
attributes[i] = 0;
str_valid = true;
break;
}
}
if (!str_valid)
cout << "Ability score doesn't exist. Pick a valid option." << endl;
} while (!str_valid);
While you can make it work your way, just using a temporary "is it valid" tracking variable makes the code a lot cleaner in this case.