Can't get data into a loop in a loop

Hello peeps

I just started on C++, and because I have a long history with another (much simpler), but I can still use my knowledge from it. I am currently stuck with a problem. Apparently I can't get information that is stored in an Array, when I try and recall it from within a loop within a loop. This is the code:

The Player string array is for storing data about the player
The chaNam string is to store data about the different classes

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

string Player[4] = { "1", "1", "1", "1" )

string chaNam[4] = { "Medic", "Blacksmith", "Archor", "King" };

 do{
		string cha;
		cout << "Choose Character: ";
		getline(cin, cha);
		
		for (int ia = 0; ia >= 3; ia++){

			if (cha == chaNam[i]){
				Player[0] = chaNam[i];

			}

			
		}
	}while (Player[0] == "1");



Thank you alot!
Nicolai

Line 11, use <= instead of >=

Edit:
I'm guessing i used in your if statement should be ia?
Last edited on
Hi Softrix

The "ia" and "i" was just guessing and trying to remove it. I though it was a bug, but it was the other thing you suggested that was the problem.

I know now that I misunderstood the information required for the function to work. When "i" is equal or lower than 3, it will work. If not, then it won't, is that correct?


Thanks!

<= is lower than or equal to.
>= is greater than or equal to.

When your loop first starts, ia is set to 0 and incremented each loop. However, your condition >= 3 would be false at the start resulting in no loop :)
I guess it is not a problem as you said "loop in a loop". So far as I see, outer loop is no problem.
The most significant mistake is the condition in the inner loop.
since 1<3, the condition will never be satified, and the inner loop will never be excuted.

Try as Softrix said, use <= instead
Topic archived. No new replies allowed.