D
D
Danil Vaskevich2021-07-14 12:00:43
C++ / C#
Danil Vaskevich, 2021-07-14 12:00:43

Why doesn't the program enter the loop?

When you enter the correct data, that is, such a name that is in the list, the program writes that the element was not found. When debugging, I realized that the program does not enter the loop. I suspect that there is a very stupid mistake somewhere. Hope for help. Code attached:

for (auto& it : menu)
{
  if (it.getName() == name)
  {
    cout << it << endl;
    return;
  }
}
cout << "There are no dish with name \"" << name << "\". Try again!" << endl;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Antony, 2021-07-14
@DaniVffgf

The definition of it.getName() and name is missing, but I already assume (although I can’t be 100% sure without the necessary pieces of code) the program almost certainly goes into a loop, bypasses the entire menu list, and each time on the condition it.getName () == name compares addresses (and they are probably different), although you probably need to compare the contents directly.
Try https://www.cplusplus.com/reference/string/string/...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question