Parallel Arrays

Hi, Im new here.

I'm having a difficulty trying to write a program with one-dimensional parallel arrays. The two arrays are the 6 ids with string and output which is 6 total of hours each id worked in integer. I also have to input hours which will add up to the total. This program would be in a loop to do as many times as I want. I got to display each arrays in the end.


So, I initialized them to
string id[6] = {"alb", "asd", "ase", "azx", "aqw", "acb"};
int total[6] = {0};
string searchId = " ";
int hours = 0;

Then I have while loop that starts the program.

Then here, how would I do to search through ids and if it doesn't match, display an error message? If it matches, ask to input the hours. I know it takes if statement...and maybe some kind of loop either while or for? because the ids are string, so it's different from just numbers.


Thanks in advance. I appreciate any comments.

Last edited on
Here's a loop that searches for a string. As you can see, processing strings isn't any more difficult than processing numners.
1
2
3
4
5
6
bool found = false;
for (int i = 0; !found  &&  i < 6; ++i)
{
    if (id[6] == "acb")
        found = true;
}
Last edited on
Topic archived. No new replies allowed.