Hi,

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;
   }

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

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

We cross posted. See my last post.

Thank you, I can't believe I didn't see that.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.