Input, display and search company data I have just learned classes and was practicing some examples from the textbook when I came to a screeching halt.

Here's the program I have written, which is complete but not optimal.  What this program does is that it inputs information about the company and then lets you display the data or search for a specific set of data.

This is a self-learning exercise, not homework and not for work either.

#include&lt;iostream&gt;
#include&lt;cstring&gt;
#include &lt;conio.h&gt;
using namespace std;

class company
{
    public:
    char companyname[20],companytype[10],companycode[5];
    int yearlyturnover;

    void displaydata()
    {
        cout&lt;&lt;companyname[20];
        cout&lt;&lt;companytype[10];
        cout&lt;&lt;companycode[5];
        cout&lt;&lt;yearlyturnover;
    }


};

int main()
{
 int count,num,option;


cout&lt;&lt;"How many companies do you want to input?:";
    cin&gt;&gt;num;

for(count=0;count&lt;num;count++)
{
    company com1[count];
    cout&lt;&lt;"\nEnter the name of the company:";
        cin.getline(com1[count].companyname,20);
    cout&lt;&lt;"\nEnter the code of the company";
        cin.getline(com1[count].companycode,5);     
    cout&lt;&lt;"\nEnter the Type of company: Public Ltd. or Private Ltd.";
        cin.getline(com1[count].companytype,10);    
    cout&lt;&lt;"\nInput the yearly turnover of the company:";
        cin&gt;&gt;com1[count].yearlyturnover;    
}

cout&lt;&lt;"\nPress 1 to display the data:";
cout&lt;&lt;"\nPress 2 to search for a company";
    cin&gt;&gt;option;
switch(option)
{

case 1: for(count=0;count&lt;num;count++)
            {
            company com1[count];
            com1[count].displaydata();
            }
        break;

case 2: for(count=0;count&lt;num;count++)
        {
            char input[10];
            company com1[count];
        cout&lt;&lt;"\nPlease enter the company type:";
            cin.getline(input,10);
        if(strcmp(input,com1[count].companytype)==0)
        {
            com1[count].displaydata();
        }   

        }
        break;


default:cout&lt;&lt;"\nError: terminating program...";    
};

 getch();
}
First, Welcome to code review, and a very nice question for a beginning self learner in C++.

user1118321 is correct about a everything he says, I'm going to emphasis one or two items and provide some references before I mention a few other things.

Use Functions:
Functions allow one to break up their code into smaller, easier to understand logical blocks. When 
designing software it is often easier to break a complex problem into smaller problems that are
easier to program. Some people use flow charts to map out their program, and high level flow
charts will only contain the functions. These will be followed by lower level flow charts that
map out the logic of each function.

Using functions allows one to decrease the amount of code written in some cases.

The main() function should be primarily used to set up the environment for the rest of the program,
call a function to execute the rest of the program and catch any errors.

If you find yourself repeating code move that code to a function so it only needs to be written and
debugged once. This is actually a programming principle generally referred to as Don't Repeat Yourself
and you may see it referred to here on code review as DRY. 

Both functions and classes should follow the Single Responsibility Principle (SRP). The Single Responsibility
Principle is that a function should do one thing, and one thing only. This makes code easier to write,
debug and maintain. It also makes the function easier to reuse.
The Single Responsibility Principle may also be a reference to Demeter's Law (I may be wrong about them being the same principle). 

Another programming principle sometimes mentioned is Keep It Simple (KISS), although this isn't just for
programming. 

You may want to look into SOLID programming as well. 

A more comprehensive list of programming principles can be found here.

Use Existing Classes
A long time ago when I started using C++ the Standard Template Library (STL), sometimes called the
Standard Library, had not yet been defined or implemented. We had to create our own strings, queues, vectors,
stacks and other container classes. Using the C++ container classes and the standard library requires
A Lot Less Code and makes it much simpler to write correct software. Two great website to become familar
with if you are going to write C++ code are CPlusPlus and the C++ reference.

These websites are better
than using a book as a reference because it remains up to date, and documents the C++11, C++14 and C++17
standards all in one place.

The string container class provides one with much more functionality then cstrings.

The follow is new content not previously mentioned.

Magic Numbers
The term magic number is sometimes used for numeric constants in code that are not obvious. By Not Obvious I mean that it's not obvious what the number represents. Non-symbolic references to numbers
should be replaced either by named constants, or enums (enumerator types). An example of a named
constant is:

constexpr double PI = 3.1415926;


Now in your code below, it is somewhat obvious what 1 and 2 are, but generally switch statements use enums or
symbolic constants.

    std::cout &lt;&lt; "\nPress 1 to display the data:";
    std::cout &lt;&lt; "\nPress 2 to search for a company";
    cin &gt;&gt; option;

    switch(option)
    {
        case 1:
           for(count = 0; count &lt; num; count++)
           {
               company com1[count];
               com1[count].displaydata();
           }
           break;

        case 2:
            for(count = 0; count &lt; num; count++)
            {
                char input[10];
                company com1[count];

                std::cout &lt;&lt; "\nPlease enter the company type:";
                cin.getline(input, 10);

                if(strcmp(input,com1[count].companytype) == 0)
                {
                    com1[count].displaydata();
                }

            }
            break;

        default:
            std::cout&lt;&lt;"\nError: terminating program...";
    };


Please note that the default case should probably have a break; statement as well, especially if is
embedded within another control statement such as a loop.

Readability and Maintainability
Making the code more readable makes it more maintainable by you or anyone else that needs to add functionality.

The code would be much more readable if it was consistently indented as I show above in the included section
of the code. Blocks of code within { and } should be indented.

Operators in control statements such as for() loops, while loops and if statement should be separated by
spaces.

Use vertical spacing to make the code easier to read as well.

In C++ and more modern languages it is more common to create variables as you need them. I would change the above
code to 

    std::cout &lt;&lt; "\nPress 1 to display the data:";
    std::cout &lt;&lt; "\nPress 2 to search for a company";

    int option;
    cin &gt;&gt; option;


This allows the maintainer to know the type of variable without jumping all over the code.

BUGS
This code may work due to the specific compiler you are using, but the fact is that you create the
company array at least 3 times. Once in every loop that I see. The variable com1 should be created
once at the top of main where count, num and option are created.

company com1[count];


The variable com1 should probably be created as
    vector com1;

This would provide a variable sized array of companies. The code for inputing the companies wouldn't change,
but the code for displaying a company or searching for a company can change:

for (auto thiscompany: com1)
{
    thiscompany.displaydata();
} 


You could use the find_if() function instead of the current search.