I want the code to sum up all three numbers with the loop but the function just sum up the total amount with the first value for three times please help.
using namespace std;
float getTotalAmount(TEST *obj)
static float totalamount=0;
totalamount = totalamount + obj->getAmount();
cout<<"Current total= "<<getTotalAmount(obj)<<endl;
When you have an array, like
using just the array name like
obj makes it decay to a pointer to its first element.
So in the loop you are calling
getTotalAmount with a pointer to the same object (
obj) all the time.
If you want to call the function for the different objects, either use
obj + i.