### Help with a simple loop

So I am working on a text based RPG and have set up the stats to come out completely random. I have made it so that the program will let you try to get better stats one time, but then it moves on to the rest of the program from there. what i would like to happen is for the program to give the user as many retries to get ideal stats for the user.

another thing i would like some info on is how to make the player able to input letters to the choice.

if i set the choice variable (stats in this case) to a 'char STATS[1];' and use 'if(STATS == "N", "n")' it just runs through the first if statement of the code instead of going to the if else statement. so could someone give me some advice on that?

 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344`` ``````#include #include #include using namespace std; int main() { srand(time(0)); int STATS; int HP = rand()%10+1; int MP = rand()%10+1; int STR = rand()%10+1; int DEF = rand()%10+1; int LUCK = rand()%10+1; cout << "HP:" << HP << ", MP:" << MP << ", STR:" << STR<< ", DEF:" << DEF << ", LUCK:" << LUCK << endl; cin >> STATS; { if(STATS == 1) { cout << "Your stats have been set." << endl; } else if(STATS == 2) { srand(time(0)); int HP = rand()%10+1; int MP = rand()%10+1; int STR = rand()%10+1; int DEF = rand()%10+1; int LUCK = rand()%10+1; cout << "HP:" << HP << ", MP:" << MP << ", STR:" << STR<< ", DEF:" << DEF << ", LUCK:" << LUCK << endl; } } return 0; }``````
Last edited on
You say char STATS[1]???
Why an array just do
char STATS
Then change 29 & 25 to STATS=='1'
And
STATS=='2'
Also add an else just so if they write @ it won't wreck the program
Last edited on
Topic archived. No new replies allowed.