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?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include<iostream>
#include<cstdlib>
#include<ctime>

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.