Making a number guessing game work
<p>I am just learning C++, I am very new to programming and this is my first language I have attempted to learn. I have have trouble making my program work though. I am just learning about if statements so I tried to make this program (I googled how to make a random number) but it just won't work. Something is wrong, I don't quite understand the "pairing" of if and else if and else but I figured this should work.</p>

<p>No matter what it tells me I have the correct number.</p>

<pre><code>#include &lt;iostream&gt;;
#include &lt;iomanip&gt;;
#include &lt;cstdlib&gt;;
#include &lt;ctime&gt;;

using namespace std;

int main()
{
    float x, y;

    srand((unsigned) time(0));

    y = rand();

    for (int index = 0; index &lt; 1; index++)
    { 
        y = (rand() % 100) + 1;

        cout &lt;&lt; y &lt;&lt; endl;
    }

    cout &lt;&lt; "Guess a number between 1 and 100 ";

    cin &gt;&gt; x;

    if (x = y)
        cout &lt;&lt; "You guessed the correct number!" &lt;&lt; endl; 
    else if (x &gt; y)
        cout &lt;&lt; "Your guess was too high" &lt;&lt; endl; 
    else
        cout &lt;&lt; "Your guess was too low" &lt;&lt; endl; 

    system("pause");

    return 0;
}
</code></pre>
