I have a for loop set up to name the elements of an array. I think I am using it wrong. Here is my code.
Code:
/* Declared variables outside of for loop */
string Heroes[9000];
int h_cost[9000];
string h_name;
int h_min;
int num_heroes;
/*For loop to set up names and cost of heroes*/
for (int h = 1; h <= num_heroes; ++h){
cout <<"What unit for Hero" <<h <<"?" <<endl;
string h_name = Heroes[h];
cin>> h_name;
cout <<"How many civs to buy this hero?" <<endl;
cin>> h_cost[h];
if (Heroes[h] == "Minerals"){
cout <<"How many minerals awarded?" <<endl;
cin>> h_min;
}
}
In essence I want the program to loop for as many heroes I have. The ouput should be similar to this....
Code:
What unit for Hero1?
Heroes name // <---value input by user
How many civs to buy this hero?
Hero cost // <---value input by user
What unit for Hero2?
Heroes name // <---value input by user
How many civs to buy this hero?
Hero cost // <---value input by user
Instead I get this....
Code:
What unit for Hero1?
Heroes name // <---value input by user
What unit for Hero2?
How many civs to buy this hero?
What unit for Hero3?
How many civs to buy this hero?
What unit for Hero3?
How many civs to buy this hero?
What unit for Hero4?
The problem is that its only letting me input the name for hero1 and just displays the rest of the questions without letting me input what I want them to be. Why isn't it letting me input values for my other heroes and costs?