I do not understand why I am getting this error: 'else' without a previous 'if'. please anyone? : <p>I am trying to write a code that would calculate the average of as many test scores as the user wants. However, when compiling it with g++ compiler, I get the error:</p>

<p>'else' without a previous 'if'</p>

<p>the only 'else' statement of the code is in the following for loop. that's why i am omitting the rest of the code. Anyone, please tell me what i am doing wrong here. I can't seem to find the answer anywhere. Thanks in advance!</p>

<pre><code>int i, j;
   cout &gt;&gt;"How many tests' scores you want to average; \n";
   cin &lt;&lt; i;

// Assuming i &gt; 0 

int test[i]

for (j = 0; j &lt; i; j++)
   {
       if (j == 0)
           cout &lt;&lt;"Enter the 1st score: \n";
           cin &gt;&gt; test[j];
       if (j == 1)
           cout &lt;&lt;"Enter the 2nd score: \n";
           cin &gt;&gt; test[j];
       if (j == 2)
           cout &lt;&lt;"Enter the 3rd score: \n";
           cin &gt;&gt; test[j];
       else
           cout &lt;&lt;"Enter the "&lt;&lt; (j+1) &lt;&lt;"th score: \n";
           cin &gt;&gt; test[j];
   }
</code></pre>
