Generate array with random numbers and search for an element in it This is a school project I've written. It works, but I feel it could be done better. 

The program generate an array of 1'000 random numbers, and searches for a number typed into console, and displays the index if found.

int inp, zuf, i, num, trig=0;
const int amount = 1000;
int arr[amount];
cout &lt;&lt; "Numbers" &lt;&lt; endl &lt;&lt; "======" &lt;&lt; endl &lt;&lt; endl;
cout &lt;&lt; "Please type in a nuber between 1 and 1000: " &lt;&lt; endl;
cin &gt;&gt; inp;
srand(time(NULL));
for (int i = 1; i &lt; amount + 1; i++) {
    zuf = rand();
    zuf = (zuf % amount) + 1;
    arr[i] = zuf;
    num = i;

    if (inp== arr[num] &amp;&amp; trig == 0) {
        cout &lt;&lt; "The number exists at the position: ";
        trig++;
    }
    if (inp== arr[num]) {
        cout &lt;&lt; num &lt;&lt; ", ";
        num++;
        trig++;
    }
}

if (trig == 0) cout &lt;&lt; "This number doesn't exist." &lt;&lt; endl;
else cout &lt;&lt; "\b\b." &lt;&lt; endl;
Do not using using namespace std

bringing in entire namespaces can be convenient, but in the long run, it's a really bad habit.

You should explicitly use std::cout and the like instead. 

Declare variables as close as possible to their first use.

int inp, zuf, i, num, trig=0;


This means very little out of context.

Prefer using std::array instead of regular c-style arrays.

std::array&lt;int, amount&gt; arr;


This plays better with the rest of the standard.

Do not use 1-based indexing unless you really need it.

And in your case, you definitely do not want it, as you are doing an out-of-bounds access on arr[i] when i == amount;

for (int i = 1; i &lt; amount + 1; i++) {


should be 

for (int i = 0; i &lt; amount; i++) {


But it doesn't matter because:

prefer using ranged-based for unless necessary

for(auto&amp; val : arr) {
  val = ...
}


Do not use srand()/rand()

They are terrible. It's slow and not particularly random. You should use the random number genreator provide by &lt;random&gt; instead:

https://en.cppreference.com/w/cpp/numeric/random/uniform_int_distribution.

Separate your concerns:

I suspect you are not respecting the "spirit of the exercise", since filling the array doesn't serve a purpose in your example.

You probably want to first fill the array, and then ask the user (possibly multiple times) to provide a number to find.