#problem with for loop
10 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.
void Select(string arr[],string a){
bool found = false;
//while the user is putting in bad inputs, it will constantly ask for a new genre choice
while(!found){
for(int x=0; x<=9; x++){
//i believe the only reason why this works best with "action" is because it is the first string in the array
if(a!=arr[x]){
cout << "idk what that is, try again \n > ";
std::cin >> a;}
break;
}
//what if you took the for loop below out of this while loop
for(int x=0; x<9; x++){
if(a==arr[x]){
std::cout << " okay so you wanna read a " + a + " book, what category of book are you intrested in?\n";
cout << "-------------------------\n";
found = true;
break;}
}
}
}```
string genre[9]={"action","thriller","romance","psychological","horror","non fiction", "fiction", "fantasy", "sci-fi", };```
I feel like its because the for loop starts at 0 and thats why it works best with the first array
but then why does it accept any ther string in the array the second time, is it the placement of my 'cin'?
```cpp
int main() {}
```
int main() {}
```cpp
int main() {}
```
int main() {}
I would reccomend stepping trough your code with a debugger to see why mistakes happen
This question thread is being automatically closed. If your question is not answered feel free to bump the post or re-ask. Take a look at !howto ask for tips on improving your question.