Program Help

#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

int main() {
double TotalInvestment;
double InitialInvestment;
float sum;

cout << fixed << showpoint << setprecision(2);

cout << "Enter the annual interest rate of investment: " << "%";
double AnnualInterestRate;
cin >> AnnualInterestRate;

cout << "Enter the initial amount of desired investment: " << "$"<<flush;
while (cin >> InitialInvestment) { //cntrl-d ends the file

if (InitialInvestment > 0) sum += TotalInvestment;
else cout <<InitialInvestment<<": negative value ignored.\n"<<flush;

TotalInvestment = InitialInvestment* pow(1.0 +AnnualInterestRate,1);

cout <<"Current Total Investment: "<<"$"<<TotalInvestment<<endl;
cout <<"Type another investment: "<<"$"<<flush;
}
cout <<"\n Overall Investment: "<<"$"<<sum<<endl;

return 0;
}
~
!g++ inv.cpp && a.out
Enter the annual interest rate of investment: %.06
Enter the initial amount of desired investment: $200
Current Total Investment: $212.00
Type another investment: $333
Current Total Investment: $352.98
Type another investment: $111
Current Total Investment: $117.66
Type another investment: $^D
Overall Investment: $564.98


I am very new to this. Well my problem is that when it calculates Overall Investment it only adds two values. Also I am not getting the rite overall investment im supposed to get 730.02. Please Help Ive been working on this for hours Thanks.
I found out my problem with the total investment not adding up. But I still need help trying to find out how to calculate this correctly. Thanks.
Topic archived. No new replies allowed.