Why does this piece of code throw me an error saying: cannot return a value from method whose result type is void?

public void orderTotal()
       int total;

       for (Order filename: Orders) {

         total = filename.getQuantity(); 


        return total;

Edited 4 Years Ago by KRUX17

Please post the full text of the error message that shows where the error occurs.
What statement causes the exception?

method whose result type is void?

The posted method is defined with return type of void on line 1. It can not return a value on line 12.
Change its return type to be the same type as total if you want to return a value.

BTW total won't be an accumulation of values, it will hold the last value received in line 7

Edited 4 Years Ago by NormR1

The error occurs on the return total; The getQuantity() method is being called from another class.

This question has already been answered. Start a new discussion instead.