Counting per topic on a quiz form

We want to have a total for each section/topic

I found a code to count totals on fields which was working on normal fields with a number but appearantly not on quiz fields with a number.

I made a hidden field for total after the 3-5 questions of eacht topic.
We want our confirmation Email to include those totals.

Code I used:

add_filter("gform_pre_submission_3", "wdm_evaluate_results452");

function wdm_evaluate_results452($form)
{

$total = 0;

// add the values of selected results
$total += $_POST["input_304"] ;
$total += $_POST["input_309"] ;
$total += $_POST["input_339"] ;

// set the value of the hidden field
$_POST["input_350"] = $total;
}

We also use the “Letter” to give a A-F result as in 0-20% 80-100% etc.
But for assessment we need the totals per category/ topic.
Since the totals are counted, I hope someone is able to help (happy to pay for it) with a customization to count per topic also for the subtotal fields on each topic