Function exit to main

Pages: 12
closed account (o10S216C)
Whats wrong with my linear search when i try to search for a name. also i would like to show all data fo
146 }
[/code]
Last edited on
logic in if statements is wrong you cant set i to 20 or it will exit loop first time make second else an else if and if (i==20) cout<<name not found;
closed account (S6k9GNh0)
You don't seem to have the right perspective of C++ logic. In this case, try and convert all of the structures (for-loop, if-else statements, etc.) into English. If you can't, go and look it up or ask us and then proceed. This should help with your comprehension a tad bit.

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

for(int i = 0; i < 20; i++)
{
   if(account[i].firstName == lookFirst) //What are you comparing here? What is lookFirst equal too?
   {
      cout << "The name " << firstName << " was found: " << endl; 
      index = i; 
      i = 20; //Setting i to 20 will cause the for loop to break;
   }
   else
   {
      cout << "The name was not found: " << endl;
      index = i; //Why are you setting index to i?
      i = 20; //Same as above.
   }
}
Topic archived. No new replies allowed.
Pages: 12