Create an array for the values, and a specific cgi-key (just a text string). Use a string consisting of cgi-key and the array index to check if the values are returned by CGI, and assign them to the respective array indices.
If you didn't get the values, display a form for the user to provide the values (of course using the cgi-key with array index as keys). If you did get the values, perform the calculations and display the results.
As for the calculations, check out all the different PHP array functions, or just perform them manually in a loop.
Also, ask further questions related to programming at Stack Overflow. And if you need help with your homework please state so in the question, and when returning your work, state publicly in the exercise group (in presence of the teacher or supervisor) where you got the help. In this way other people learn of the resource too so they can get help learning as well. There's nothing wrong in asking for information to undestand a problem, but hiding the fact that it's your homework does seems quite dubious...